Metodo XML DOM hasChildNodes()
❮ Oggetto Elemento
Esempio
Il seguente frammento di codice carica " books.xml " in xmlDoc e controlla 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 dell'elemento corrente ha nodi figlio e FALSE in caso contrario.
Sintassi
elementNode.hasChildNodes()
❮ Oggetto Elemento