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 --- files/fr/web/api/node/haschildnodes/index.md | 90 ++++++++++++---------------- 1 file changed, 39 insertions(+), 51 deletions(-) (limited to 'files/fr/web/api/node/haschildnodes') diff --git a/files/fr/web/api/node/haschildnodes/index.md b/files/fr/web/api/node/haschildnodes/index.md index c14ad9836f..54fd502016 100644 --- a/files/fr/web/api/node/haschildnodes/index.md +++ b/files/fr/web/api/node/haschildnodes/index.md @@ -10,69 +10,57 @@ tags: - Reference translation_of: Web/API/Node/hasChildNodes --- -

{{APIRef("DOM")}}

+{{APIRef("DOM")}} -

La méthode Node.hasChildNodes() renvoie un {{jsxref("Boolean")}} indiquant si le {{domxref("Node","noeud")}} actuel possède des nœuds enfants ou non.

+La méthode **`Node.hasChildNodes()`** renvoie un {{jsxref("Boolean")}} indiquant si le {{domxref("Node","noeud")}} actuel possède des [nœuds enfants](/fr/docs/Web/API/Node/childNodes) ou non. -

Syntaxe

+## Syntaxe -
bool = node.hasChildNodes();
+```js +bool = node.hasChildNodes(); +``` -

Valeur de retour

+### Valeur de retour -

Un {{jsxref("Boolean")}} qui est true si le nœud a des nœuds enfants, et false dans le cas contraire.

+Un {{jsxref("Boolean")}} qui est `true` si le nœud a des nœuds enfants, et `false` dans le cas contraire. -

Exemple

+## Exemple -
let foo = document.getElementById('foo');
+```js
+let foo = document.getElementById('foo');
 
 if (foo.hasChildNodes()) {
   // Faire quelque chose avec 'foo.childNodes'
-}
+} +``` -

Prothèse d'émulation

+## Prothèse d'émulation -
(function(prototype) {
+```js
+(function(prototype) {
   prototype.hasChildNodes = prototype.hasChildNodes || function() {
     return !!this.firstChild;
   }
-})(Node.prototype);
- -

Il y a différentes façons de déterminer si le noeud a un noeud enfant :

- - - -

Spécification

- - - - - - - - - - - - - - - - -
SpécificationStatutCommentaire
{{SpecName("DOM WHATWG", "#dom-node-haschildnodes", "Node: hasChildNodes")}} - {{Spec2("DOM WHATWG")}}
- -

Compatibilité des navigateurs

- -

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

- -

Voir aussi

- - +})(Node.prototype); +``` + +Il y a différentes façons de déterminer si le noeud a un noeud enfant : + +- `node.hasChildNodes()` +- `node.firstChild != null` (ou simplement `node.firstChild`) +- `node.childNodes && node.childNodes.length` (ou `node.childNodes.length > 0`) + +## Spécification + +| Spécification | Statut | Commentaire | +| ---------------------------------------------------------------------------------------------------- | -------------------------------- | ----------- | +| {{SpecName("DOM WHATWG", "#dom-node-haschildnodes", "Node: hasChildNodes")}} | {{Spec2("DOM WHATWG")}} | | + +## Compatibilité des navigateurs + +{{Compat("api.Node.hasChildNodes")}} + +## Voir aussi + +- {{domxref("Node.childNodes")}} +- {{domxref("Node.hasAttributes")}} -- cgit v1.2.3-54-g00ecf