Metodo XML DOM hasChildNodes()
❮ Oggetto nodo
Esempio
Il seguente frammento di codice carica " books.xml " in xmlDoc e restituisce se il primo elemento <book> ha nodi figlio:
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.hasChildNodes();
}
L'output del codice sopra sarà:
true
Definizione e utilizzo
Il metodo hasChildNodes() restituisce true se il nodo specificato ha nodi figlio, altrimenti false .
Supporto del browser
Il metodo hasChildNodes() è supportato in tutti i principali browser.
Sintassi
nodeObject.hasChildNodes()
Parametri
Nessuno.
Valore di ritorno
Type | Description |
---|---|
Boolean | Returns true if the specified node has any child nodes, otherwise false |
Dettagli tecnici
Versione DOM | Oggetto nodo di livello 1 principale |
---|
❮ Oggetto nodo