compareDocumentPosition

The compareDocumentPosition() method of the Node interface reports the position of its argument node relative to the node on which it is called.

MDN Reference