Metodo XML DOM hasAttributes()

Definizione e uso

Se l'elemento nodo corrente ha qualsiasi attributo, allora hasAttributes() Il metodo restituisce true, altrimenti restituisce false.

Sintassi

hasAttributes()

Esempio

Il codice seguente carica "books.xml" nel xmlDoc e verifica se l'elemento <book> ha qualsiasi attributo:

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();
}

亲自试一试