compareDocumentPosition

The compareDocumentPosition JS Node returns a bitmask indicating the position of other relative to node.

Name Number Description
Node.DOCUMENT_POSITION_DISCONNECTED 1 Other is not in the same tree as node
Node.DOCUMENT_POSITION_PRECEDING 2 Other precedes node
Node.DOCUMENT_POSITION_FOLLOWING 4 Other follows node
Node.DOCUMENT_POSITION_CONTAINS 8 Other is an ancestor of node
Node.DOCUMENT_POSITION_CONTAINED_BY 16 (10 in hexadecimal) Other is a descendant of node
Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC 32 (20 in hexadecimal) Other is implementation-specific relative to node

Syntax

node.compareDocumentPosition(other)

Parameters

other

A node.

Examples

1

2

3

4

5

6

baseURI

childNodes

cloneNode

contains

firstChild

getRootNode

hasChildNodes

isConnected

isEqualNode

lastChild

nextSibling

nodeName

nodeType

normalize

ownerDocument

parentElement

parentNode

previousSibling

Web Hypertext Application Technology Working Group (WHATWG)

Home Menu