Metodo XML DOM hasAttributes()
❮ Oggetto nodo
Esempio
Il seguente frammento di codice carica " books.xml " in xmlDoc e restituisce se il primo elemento <book> ha 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 specificato ha attributi, altrimenti false .
Nota: se il nodo specificato non è un nodo Element, il valore restituito è sempre false .
Supporto browser
Il metodo hasAttributes() è supportato in tutti i principali browser.
Nota: Internet Explorer 9 e versioni precedenti non supportano il metodo hasAttributes().
Sintassi
nodeObject.hasAttributes()
Parametri
Nessuno.
Valore di ritorno
Type | Description |
---|---|
Boolean | Returns true if the specified node has any attributes, otherwise false |
Dettagli tecnici
Versione DOM | Oggetto nodo di livello 2 di base |
---|
❮ Oggetto nodo