[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ru/docs/Web/API/Node/compareDocumentPosition [Back]  [Original]

Node: compareDocumentPosition() - API | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Node: compareDocumentPosition()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 ..

compareDocumentPosition() Node , .

In this article

js
compareDocumentPosition(otherNode)

otherNode

Node, , .

, otherNode node , Node:

Node.DOCUMENT_POSITION_DISCONNECTED (1)

.

Node.DOCUMENT_POSITION_PRECEDING (2)

otherNode .

Node.DOCUMENT_POSITION_FOLLOWING (4)

otherNode .

Node.DOCUMENT_POSITION_CONTAINS (8)

otherNode .

Node.DOCUMENT_POSITION_CONTAINED_BY (16)

otherNode .

Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC (32)

/ , .

. , otherNode , compareDocumentPosition(), DOCUMENT_POSITION_CONTAINS DOCUMENT_POSITION_PRECEDING, 10 (0x0A).

js
const head = document.head;
const body = document.body;

if (head.compareDocumentPosition(body) & Node.DOCUMENT_POSITION_FOLLOWING) {
  console.log("  ");
} else {
  console.error("<head>    <body>");
}

: , compareDocumentPosition(), , .

Specification
DOM
# ref-for-dom-node-comparedocumentposition


Web Proxy Viewer  |  New URL  |  Original Page