XML DOM hasAttribute()Méthodes
Objet Element
Définition et utilisation
La méthode hasAttribute() renvoie TRUE si le nœud d'élément courant possède un attribut correspondant au nom spécifié, sinon elle renvoie FALSE.
Syntaxe
hasAttribute(name)
| Paramètre | Description |
|---|---|
| name | Obligatoire. Spécifie l'attribut à rechercher. |
Exemple
L'extrait de code suivant utiliseloadXMLDoc()pour charger "" dans xmlDoc, et vérifie si le premier élément <book> possède un attribut "category" :"
Exemple
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("book")[0];
document.write(x.hasAttribute("category"));
x=xmlDoc.getElementsByTagName("book")[0];
document.write(x.hasAttribute("category"));
Sortie :
vrai
Essayez-le vous-même »
Objet Elementautres extensions