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:-
ValueMeaning 1The nodes do not belong to the same document 2The first node is positioned after the second 4The first node is positioned before the second 8The first node is positioned inside the second 16The second node is positioned inside the first 32The 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:-
ParameterDescription NodeRequired. The node to compare with the current node.