HTML DOM Element compareDocumentPosition()
HTML DOM Element compareDocumentPosition() Method
The compareDocumentPosition() method is used for comparing two nodes. It returns an integer to describe their position in the document. Some positions are:-
Value | Meaning |
---|---|
1 | The nodes do not belong to the same document |
2 | The first node is positioned after the second |
4 | The first node is positioned before the second |
8 | The first node is positioned inside the second |
16 | The second node is positioned inside the first |
32 | The nodes are attributes on the same element |
The return value can also be a combination of values.
Syntax:-
Its syntax is:- node.compareDocumentPosition(node)
Return:-
Its return is:- a number representing two nodes that are positioned when compared to each other
Further Explanation:-
Parameter | Description |
Node | Required. The node to compare with the current node. |