XML DOM nodeType 屬性

定義和用法

nodeType 屬性返回被選節點的節點類型。

語法:

elementNode.nodeType
節點編號: 節點名稱:
1 Element
2 Attribute
3 Text
4 CDATA Section
5 Entity Reference
6 Entity
7 Processing Instrucion
8 Comment
9 Document
10 Document Type
11 Document Fragment
12 Notation

實例

在所有的例子中,我們將使用 XML 文件 books.xml,以及 JavaScript 函數 loadXMLDoc()

下面的代碼片段獲取 "books.xml" 的第一個 <title> 元素的節點類型:

xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title")[0];
document.write(x.nodeType);

以上代碼的輸出:

1