Thuộc tính nodeType của XML DOM

Định nghĩa và cách sử dụng

Thuộc tính nodeType trả về loại nút của nút được chọn.

Cú pháp:

elementNode.nodeType
Số thứ tự nút: Tên nút:
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

Ví dụ

Trong tất cả các ví dụ, chúng ta sẽ sử dụng tệp XML books.xmlvà hàm JavaScript loadXMLDoc()

Đoạn mã sau đây lấy loại nút của phần tử <title> đầu tiên trong "books.xml":

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

Kết quả của đoạn mã trên:

1