Propiedad de longitud de DOM XML
❮ Objeto NamedNodeMap
Ejemplo
El siguiente fragmento de código carga " books.xml " en xmlDoc y obtiene la cantidad de atributos en el primer elemento <book>:
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");
document.getElementById("demo").innerHTML =
"Number of
attributes in the first book element: " +
x.item(0).attributes.length;
}
La salida del código anterior será:
Number of attributes in the first book element:
1
Definición y uso
La propiedad de longitud devuelve el número de nodos en un NamedNodeMap.
Sintaxis
nodemapObject.length
Demostraciones para que lo pruebe usted mismo
❮ Objeto NamedNodeMap