The Node.compareDocumentPosition() method compares the position of the given node against another node in any document.
The other Node with which to compare document positioning.
An integer value whose bits represent the calling Node's relationship to otherNode within the Document. More than one of the bits may be set, if multiple scenarios apply. If otherNode is located earlier in the document and also contains the Node on which compareDocumentPosition() was called, then the DOCUMENT_POSITION_CONTAINS and DOCUMENT_POSITION_PRECEDING bits would be set, resulting in a value of 0x0A or decimal 10.
Note: Because the result returned by compareDocumentPosition() is a bitmask, the bitwise AND operator has to be used for meaningful results.
Note that the first statement above uses the NodeList.item() method with a parameter value of 0, which is equivalent to getElementsByTagName('head').