Méthode XML DOM hasAttributes()

Définition et utilisation

Si l'élément courant possède des attributs, alors hasAttributes() La méthode renvoie true, sinon false.

Syntaxe

hasAttributes()

Exemple

Le code suivant charge "books.xml" dans xmlDoc et vérifie si le premier élément <book> possède des attributs :

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName('book')[0];
    document.getElementById("demo").innerHTML =
    x.hasAttributes();
}

Essayer personnellement