Délka XML DOM Vlastnost
❮ Objekt NamedNodeMap
Příklad
Následující fragment kódu načte " books.xml " do xmlDoc a získá počet atributů v prvním prvku <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;
}
Výstupem výše uvedeného kódu bude:
Number of attributes in the first book element:
1
Definice a použití
Vlastnost length vrací počet uzlů v NamedNodeMap.
Syntax
nodemapObject.length
Vyzkoušejte si ukázky
❮ Objekt NamedNodeMap