Proprietà lunghezza DOM XML
❮ Oggetto di testo
Esempio
Il seguente frammento di codice carica " books.xml " in xmlDoc e stampa i dati e la lunghezza del nodo di testo dal primo elemento <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")[0].childNodes[0];
document.getElementById("demo").innerHTML =
x.data + "
- Length: " + x.length;
}
L'output del codice sopra sarà:
Everyday Italian - Length: 16
Definizione e utilizzo
La proprietà length restituisce la lunghezza del testo di un nodo (in caratteri).
Sintassi
textNode.length
❮ Oggetto di testo