English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
MethodThe method is to compare the position of the given node with any other node in any document.
The return value is a bitmask with the following values:
Name | Values |
---|---|
DOCUMENT_POSITION_DISCONNECTED | 1 |
DOCUMENT_POSITION_PRECEDING | 2 |
DOCUMENT_POSITION_FOLLOWING | 4 |
DOCUMENT_POSITION_CONTAINS | 8 |
DOCUMENT_POSITION_CONTAINED_BY | 16 |
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | 32 |
node.compareDocumentPosition(node)
Example1 var p1= document.getElementById("p Example2 var p2= document.getElementById("p ").lastChild;1var x = p2.compareDocumentPosition(p);/Test and see‹
Browser Compatibility
All browsers fully support the compareDocumentPosition() method: | |||||
Method | compareDocumentPosition() | compareDocumentPosition() | compareDocumentPosition() | compareDocumentPosition() | compareDocumentPosition() |
Parameter Value | Parameter |
---|---|
Description | node |
Technical Details | Return value: A number representing the position between the two nodes. 1Possible return values: 2).Is located before the second node (p1).Is located after the first node (p2).There is no relationship, the two nodes do not belong to the same document. 4).Is located before the second node (p1).Is located after the first node (p2).Is located after the second node (p 8).Is located before the first node (p1).Is located at the second node (p2).Inside. 16).The second node (p2).Is located at the first node (p1).Inside. 32There is no relationship, or two nodes are two attributes on the same element. |
---|---|
DOM Version: | DOM Level1 |