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
var result = element.hasAttributes();
Valeur de retour
result
-
contient la valeur de retour
true
oufalse
.
Exemple
var foo = document.getElementById("foo");
if (foo.hasAttributes()) {
// faire quelque chose avec 'foo.attributes'
}
Polyfill
;(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