来源:https://developer.mozilla.org/en/DOM/Node.compareDocumentPosition
Summary
Compares the position of the current node against another node in any other document.
Syntax
node.compareDocumentPosition( otherNode )
-
node
is the node that's being compared. -
otherNode
is the node that's being compared against.
The return value is computed as the relationship thatotherNode
has withnode
.
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