XMLDOMの長さのプロパティ
❮NamedNodeMapオブジェクト
例
次のコードフラグメントは、「books.xml」をxmlDocにロードし、最初の<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;
}
上記のコードの出力は次のようになります。
Number of attributes in the first book element:
1
定義と使用法
lengthプロパティは、NamedNodeMap内のノードの数を返します。
構文
nodemapObject.length
試してみるデモ
❮NamedNodeMapオブジェクト