Propriedade de comprimento XML DOM
❮ Objeto de texto
Exemplo
O fragmento de código a seguir carrega " books.xml " em xmlDoc e imprime os dados do nó de texto e o comprimento do primeiro 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;
}
A saída do código acima será:
Everyday Italian - Length: 16
Definição e uso
A propriedade length retorna o comprimento do texto de um nó (em caracteres).
Sintaxe
textNode.length
❮ Objeto de texto