element.hasAttributes
La méthode hasAttributes(), rattachée à l'interface Element, renvoie une valeur booléenne indiquant si le nœud courant a au moins un attribut ou non.
Syntaxe
js
var result = element.hasAttributes();
Valeur de retour
result-
contient la valeur de retour
trueoufalse.
Exemple
js
var foo = document.getElementById("foo");
if (foo.hasAttributes()) {
// faire quelque chose avec 'foo.attributes'
}
Polyfill
js
;(function(prototype) {
prototype.hasAttributes = prototype.hasAttributes || function() {
return (this.attributes.length > 0);
}
})(Element.prototype);
Spécifications
| Specification |
|---|
| DOM Standard # ref-for-dom-element-hasattributes① |
Compatibilité des navigateurs
BCD tables only load in the browser