Metodo XML DOM hasAttributes()
❮ Oggetto Elemento
Esempio
Il seguente frammento di codice carica " books.xml " in xmlDoc e controlla se il primo elemento <book> ha degli attributi:
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();
}
Produzione:
true
Definizione e utilizzo
Il metodo hasAttributes() restituisce TRUE se il nodo dell'elemento corrente ha degli attributi e FALSE in caso contrario.
Sintassi
hasAttributes()
❮ Oggetto Elemento