Easy Tutorial
❮ Dom Nodes Clone Dom Parser ❯

XML DOM compareDocumentPosition() Method



Definition and Usage

The compareDocumentPosition() method compares the document position of the current node with a specified node, according to the document order.

Syntax

Parameter Description
node Required. Specifies the node to compare with the current node.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc and compares the first and third <book> nodes:

Example

Output:

Firefox and most other browsers treat empty spaces or line breaks between nodes as text nodes, while Internet Explorer ignores empty text nodes generated between nodes. Therefore, in the above example, Mozilla browsers will output 4, and Internet Explorer will output 2.

For more information on browser differences, visit the DOM Browsers section in our XML DOM tutorial.


❮ Dom Nodes Clone Dom Parser ❯