You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **`compareDocumentPosition()`** method of the {{domxref("Node")}} interface
12
-
reports the position of its argument node relative to the node on which it is called.
11
+
The **`compareDocumentPosition()`** method of the {{domxref("Node")}} interface reports the position of its argument node relative to the node on which it is called.
An integer value representing `otherNode`'s position relative to `node`
28
-
as a [bitmask](<https://en.wikipedia.org/wiki/Mask_(computing)>) combining the
29
-
following constant properties of {{domxref("Node")}}:
26
+
An integer value representing `otherNode`'s position relative to `node` as a [bitmask](<https://en.wikipedia.org/wiki/Mask_(computing)>) combining the following constant properties of {{domxref("Node")}} or `0` if `otherNode` is the same as this node:
30
27
31
28
-`Node.DOCUMENT_POSITION_DISCONNECTED` (`1`)
32
29
- : Both nodes are in different documents or different trees in the same document.
@@ -41,11 +38,8 @@ following constant properties of {{domxref("Node")}}:
- : The result relies upon arbitrary and/or implementation-specific behavior and is not guaranteed to be portable.
43
40
44
-
Zero or more bits can be set, depending on which scenarios apply. For example, if
45
-
`otherNode` is located earlier in the document **_and_**
46
-
contains the node on which `compareDocumentPosition()` was
47
-
called, then both the `DOCUMENT_POSITION_CONTAINS` and
48
-
`DOCUMENT_POSITION_PRECEDING` bits would be set, producing a value of `10` (`0x0A`).
41
+
Zero or more bits can be set, depending on which scenarios apply.
42
+
For example, if `otherNode` is located earlier in the document **_and_** contains the node on which `compareDocumentPosition()` was called, then both the `DOCUMENT_POSITION_CONTAINS` and `DOCUMENT_POSITION_PRECEDING` bits would be set, producing a value of `10` (`0x0A`).
49
43
50
44
## Example
51
45
@@ -61,9 +55,7 @@ if (head.compareDocumentPosition(body) & Node.DOCUMENT_POSITION_FOLLOWING) {
61
55
```
62
56
63
57
> [!NOTE]
64
-
> Because the result returned by `compareDocumentPosition()` is a bitmask,
65
-
> the [bitwise AND operator](/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND)
66
-
> must be used for meaningful results.
58
+
> Because the result returned by `compareDocumentPosition()` is a bitmask, the [bitwise AND operator](/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND) must be used for meaningful results.
0 commit comments