compareDocumentPosition

Returns a bitmask indicating the position of other relative to node.

MDN Reference