Table of contents
- 1. Summary
- 2. Syntax
- 3. Notes
- 4. Example
- 5. Specification
Summary
Compares the position of the current node against another node in any other document.
Syntax
node.compareDocumentPosition( otherNode )
nodeis the node that's being compared.otherNodeis the node that's being compared against.
The return value is computed as the relationship that otherNode has with node.
Notes
The return value is a bitmask with the following values:
DOCUMENT_POSITION_DISCONNECTED = 1; DOCUMENT_POSITION_PRECEDING = 2; DOCUMENT_POSITION_FOLLOWING = 4; DOCUMENT_POSITION_CONTAINS = 8; DOCUMENT_POSITION_CONTAINED_BY = 16;
Example
var head = document.getElementsByTagName('head').item(0);
var result = head.compareDocumentPosition(document.body);
// result = head.DOCUMENT_POSITION_FOLLOWING


Mozilla Developer Network