Easy Tutorial
❮ Prop Node Localname Dom Met Node Issamenode ❯

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 document positions of the first and third <book> elements:

Example

Output:

Firefox and most other browsers treat spaces or line breaks generated between nodes as text nodes, while Internet Explorer ignores whitespace 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.


❮ Prop Node Localname Dom Met Node Issamenode ❯