Element : méthode hasAttributeNS()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
La méthode hasAttributeNS()
, associée à l'interface Element
, renvoie une valeur booléenne indiquant si l'élément courant possède l'attribut spécifié ou non pour l'espace de noms indiqué.
Si vous manipulez des documents HTML et n'avez pas besoin de restreindre à un espace de noms donné, vous pouvez utiliser la méthode hasAttribute()
à la place.
Syntaxe
hasAttributeNS(namespace,localName)
Paramètres
Valeur de retour
Un booléen indiquant la présence de l'attribut.
Exemple
// Check that the attribute exists before you set a value
const d = document.getElementById("div1");
if (
d.hasAttributeNS("http://www.mozilla.org/ns/specialspace/", "special-align")
) {
d.setAttribute("align", "center");
}
Spécifications
Specification |
---|
DOM # ref-for-dom-element-hasattributens① |
Compatibilité des navigateurs
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
hasAttributeNS |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support