Proprietà lunghezza DOM XML
❮ Oggetto NodeList
Esempio
Il seguente frammento di codice carica " books.xml " in xmlDoc e ottiene il numero di elementi <title>:
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("title");
document.getElementById("demo").innerHTML =
"Number of
title elements: " + x.length;
}
L'output del codice sopra sarà:
Number of title elements: 4
Definizione e utilizzo
La proprietà length restituisce il numero di nodi in un elenco di nodi.
Sintassi
nodelistObject.length
Dimostrazioni fai-da-te
❮ Oggetto NodeList