jQuery isXMLDoc() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Utilities

Definition

jQuery.isXMLDoc(node) (alias $.isXMLDoc) returns true when node is an XML document or a DOM node inside an XML document (added in jQuery 1.1.4).

Syntax

Start with these common calls. Keep them short and readable.

jQuery
$.isXMLDoc(node)  → true | false

$.isXMLDoc(document)       // false  (HTML page)
$.isXMLDoc(document.body)  // false  (HTML page)

xmlDoc = $.parseXML("<root/>")
$.isXMLDoc(xmlDoc)         // true
$.isXMLDoc(xmlDoc.documentElement)  // true
CallWhat it does
isXMLDoc()Learn jQuery.isXMLDoc(): detect XML documents and XML DOM nodes vs HTML pages, pair with parseXML(), examples, pitfalls, and FAQs.

Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.

Parameters

ParameterDescription
Step 1Start with a DOM node (page node, AJAX XML node, or parsed XML).
Step 2Call $.isXMLDoc(node) — true means XML context.
Step 3If you only have a string, parse first with $.parseXML.

Return Value

Return ValueDescription
BooleanOften true or false depending on the match or state.
Value / undefinedGetters usually return a value from the first matched element, or undefined when nothing applies.

jQuery Examples

Example 1 — Official HTML Page Checks

The jQuery API samples: page document and body are not XML.

jQuery
console.log($.isXMLDoc(document));       // false
console.log($.isXMLDoc(document.body));  // false
Try It Yourself

How It Works

  1. HTML document. The page root is <html>, not an XML root.
  2. Body node. document.body lives in that same HTML document.
  3. Result. Both official samples return false.

Example 2 — XML Document from $.parseXML()

Parsed XML produces a real XMLDocument.

jQuery
var xmlDoc = $.parseXML("<root><item/></root>");

console.log($.isXMLDoc(xmlDoc));                 // true
console.log($.isXMLDoc(xmlDoc.documentElement)); // true
Try It Yourself

How It Works

  1. Parse. $.parseXML builds a native XML document.
  2. Document. The return value itself is an XML document → true.
  3. Root element. documentElement is the <root> node inside that XML tree.

Example 3 — A Child Node Inside XML

Any node from the XML tree also returns true.

jQuery
var xmlDoc = $.parseXML(
  '<rss><channel><title>Feed</title></channel></rss>'
);
var title = $(xmlDoc).find("title")[0];

console.log($.isXMLDoc(title));           // true
console.log($.isXMLDoc(document.body));   // false
Try It Yourself

How It Works

  1. Parse RSS-like XML. Build a small XML tree with a title.
  2. Find. .find("title")[0] unwraps the native node.
  3. XML child. That node belongs to the XML document → true.

Frequently Asked Questions

jQuery.isXMLDoc(node) returns true when node is an XML document or a DOM node inside an XML document. It returns false for nodes on a normal HTML page — including document and document.body.
Normal web pages use an HTML document whose root is <html>. The official jQuery API shows both document and document.body return false. Use isXMLDoc for XML contexts — RSS, AJAX XML, or strings parsed with $.parseXML().
Yes. After $.parseXML("<root/>"), the returned XMLDocument and its child elements return true from $.isXMLDoc(). That is the usual way beginners create XML nodes in jQuery.
Both HTML and XML nodes often look like objects. isXMLDoc checks whether the node belongs to an XML document — a specialized DOM check, not a generic type string.
Pass a real DOM node (or document). Prefer validating the value first. Falsy or non-node input is not useful and may behave differently across older jQuery builds.
When the same helper must branch between HTML page nodes and XML trees — for example choosing selectors, namespaces, or how to read text from feed items.

Next: contains() Method

Learn how jQuery checks whether one DOM element contains another.

contains() Method tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful