From 1407c8fdef01ecd0ffb8a8bd46e7113f119b9fde Mon Sep 17 00:00:00 2001 From: julieng Date: Sat, 2 Oct 2021 17:20:24 +0200 Subject: convert content to md --- .../web/api/node/comparedocumentposition/index.md | 139 +++++++-------------- 1 file changed, 46 insertions(+), 93 deletions(-) (limited to 'files/fr/web/api/node/comparedocumentposition') diff --git a/files/fr/web/api/node/comparedocumentposition/index.md b/files/fr/web/api/node/comparedocumentposition/index.md index a40125b5c1..21bc78963d 100644 --- a/files/fr/web/api/node/comparedocumentposition/index.md +++ b/files/fr/web/api/node/comparedocumentposition/index.md @@ -10,99 +10,52 @@ tags: - Position translation_of: Web/API/Node/compareDocumentPosition --- -
{{APIRef("DOM")}}
- -

La méthode Node.compareDocumentPosition()compare la position du noeud courant par rapport à un autre noeud dans tout autre document.

- -

La valeur retournée est un masque de bits avec les valeurs suivantes :

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NomValeur
DOCUMENT_POSITION_DISCONNECTED1
DOCUMENT_POSITION_PRECEDING2
DOCUMENT_POSITION_FOLLOWING4
DOCUMENT_POSITION_CONTAINS8
DOCUMENT_POSITION_CONTAINED_BY16
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC32
- -

Syntaxe

- -
node.compareDocumentPosition( otherNode )
-
- -

Exemple

- -
var head = document.getElementsByTagName('head').item(0);
-
-if (head.compareDocumentPosition(document.body) & Node.DOCUMENT_POSITION_FOLLOWING) {
+{{APIRef("DOM")}}
+
+La méthode **`Node.compareDocumentPosition()`**compare la position du noeud courant par rapport à un autre noeud dans tout autre document.
+
+La valeur retournée est un masque de bits avec les valeurs suivantes :
+
+| Nom                                         | Valeur |
+| ------------------------------------------- | ------ |
+| `DOCUMENT_POSITION_DISCONNECTED`            | 1      |
+| `DOCUMENT_POSITION_PRECEDING`               | 2      |
+| `DOCUMENT_POSITION_FOLLOWING`               | 4      |
+| `DOCUMENT_POSITION_CONTAINS`                | 8      |
+| `DOCUMENT_POSITION_CONTAINED_BY`            | 16     |
+| `DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC` | 32     |
+
+## Syntaxe
+
+    node.compareDocumentPosition( otherNode )
+
+## Exemple
+
+```js
+var head = document.getElementsByTagName('head').item(0);
+
+if (head.compareDocumentPosition(document.body) & Node.DOCUMENT_POSITION_FOLLOWING) {
   console.log("well-formed document");
 } else {
-  console.log("<head> is not before <body>");
+  console.log(" is not before ");
 }
-
- -
-

Note : Parce que le résultat renvoyé par compareDocumentPosition est un masque de bits, des opérateurs binaires doivent être utilisés pour des résultats significatifs.

-
- -
-

Note : La première instruction utilise l' item(0) de la méthode NodeList , qui est l'équivalent de getElementsByTagName('head')[0].

-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationStatutCommentaire
{{SpecName('DOM WHATWG','#dom-node-comparedocumentposition','Node.compareDocumentPosition()')}}{{Spec2('DOM WHATWG')}} 
{{SpecName('DOM3 Core','core.html#Node3-compareDocumentPosition','Node.compareDocumentPosition()')}}{{Spec2('DOM3 Core')}}Définition initiale
- -

Compatibilité des navigateurs

- -

{{Compat("api.Node.compareDocumentPosition")}}

- -

Voir aussi

- - +``` + +> **Note :** Parce que le résultat renvoyé par\* \*`compareDocumentPosition` est un masque de bits, des [opérateurs binaires](/fr/docs/Web/JavaScript/Reference/Op%C3%A9rateurs/Op%C3%A9rateurs_binaires) doivent être utilisés pour des résultats significatifs. + +> **Note :** La première instruction utilise l' `item(0)` de la méthode [NodeList](/en-US/docs/Web/API/NodeList/item) , qui est l'équivalent de `getElementsByTagName('head')[0].` + +## Spécifications + +| Spécification | Statut | Commentaire | +| ------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------- | ------------------- | +| {{SpecName('DOM WHATWG','#dom-node-comparedocumentposition','Node.compareDocumentPosition()')}} | {{Spec2('DOM WHATWG')}} |   | +| {{SpecName('DOM3 Core','core.html#Node3-compareDocumentPosition','Node.compareDocumentPosition()')}} | {{Spec2('DOM3 Core')}} | Définition initiale | + +## Compatibilité des navigateurs + +{{Compat("api.Node.compareDocumentPosition")}} + +## Voir aussi + +- [`Node.contains`](/fr/docs/Web/API/Node/contains) -- cgit v1.2.3-54-g00ecf