--- title: element.hasChildNodes slug: Web/API/Node/hasChildNodes tags: - API - DOM - Enfant - Méthodes - Noeuds translation_of: Web/API/Node/hasChildNodes ---
{{APIRef("DOM")}}
La méthode Node.hasChildNodes() renvoie une valeur booléenne indiquant si le {{domxref("Node","noeud")}} actuel possède des nœuds enfants ou non.
resultat =element.hasChildNodes();
L'exemple suivant supprime le premier noeud enfant à l'intérieur de l'élément avec l'identifiant "foo" si "foo" a des noeuds enfant.
var foo = document.getElementById("foo");
if (foo.hasChildNodes()) {
// faire quelque chose avec les 'foo.childNodes'
}
;(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 :
{{CompatibilityTable}}
| Fonctionnalité | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | 7.0 | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
| Fonctionnalité | Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |