--- title: element.hasAttributes slug: Web/API/Element/hasAttributes tags: - API - DOM - Element - Méthode - Reference - polyfill translation_of: Web/API/Element/hasAttributes ---
La méthode hasAttributes(), rattachée à l'interface {{domxref("Element")}}, renvoie une valeur booléenne indiquant si le nœud courant a au moins un attribut ou non.
var result = element.hasAttributes();
resulttrue ou false.var foo = document.getElementById("foo");
if (foo.hasAttributes()) {
// faire quelque chose avec 'foo.attributes'
}
;(function(prototype) {
prototype.hasAttributes = prototype.hasAttributes || function() {
return (this.attributes.length > 0);
}
})(Element.prototype);
| Spécification | Statut | Commentaire |
|---|---|---|
| {{SpecName("DOM WHATWG", "#dom-element-hasattributes", "Element.hasAttributes()")}} | {{Spec2('DOM WHATWG')}} | Déplacé de l'interface {{domxref("Node")}} vers l'interface plus spécialisée {{domxref("Element")}}. |
| {{SpecName('DOM3 Core','#ID-NodeHasAttrs','hasAttributes()')}} | {{Spec2('DOM3 Core')}} | Pas de changement par rapport à {{SpecName("DOM2 Core")}} |
| {{SpecName('DOM2 Core','#ID-NodeHasAttrs','hasAttributes()')}} | {{Spec2('DOM2 Core')}} | Définition initiale, sur l'interface {{domxref("Node")}}. |
{{Compat("api.Element.hasAttributes")}}