XML DOMnodeTypeプロパティ
❮要素オブジェクト
例
次のコードフラグメントは、「books.xml」をxmlDocにロードし、最初の<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];
document.getElementById("demo").innerHTML =
x.nodeType;
}
上記のコードの出力は次のようになります。
1
定義と使用法
nodeTypeプロパティは、選択したノードのノードタイプを返します。
構文
elementNode.nodeType
Node Number: | Node Name: |
---|---|
1 | Element |
2 | Attribute |
3 | Text |
4 | CDATA Section |
5 | Entity Reference |
6 | Entity |
7 | Processing Instruction |
8 | Comment |
9 | Document |
10 | Document Type |
11 | Document Fragment |
12 | Notation |
試してみるデモ
❮要素オブジェクト