HTML DOM nodeType property
Definition and Usage
nodeType property returns the node type.
If the node is an element node, nodeType property returns -1.
If the node is an attribute node, nodeType property returns 2.
Browser Support
All major browsers support the nodeType property
grammar
node .nodeType
technical details
return value: | String, the representative node type of the node. |
---|---|
DOM version | Core Level 1 Node Object |
Node Type
An HTML or XML document files, elements, attributes, etc. There are different types of nodes.
There are 12 different types of nodes, different node types can have different types of child nodes:
节点类型 | 描述 | 子节点 | |
---|---|---|---|
1 | Element | 一个元素 | Element, Text, Comment, ProcessingInstruction, CDATASection, Entity参考手册 |
2 | Attr | 一个属性 | Text, Entity参考手册 |
3 | Text | 一个元素的文本内容 或属性 | None |
4 | CDATASection | 一个文档的CDATA部分(文本将 不会被解析器解析) | None |
5 | Entity参考手册 | 实体引用 | Element, ProcessingInstruction, Comment, Text, CDATASection, Entity参考手册 |
6 | Entity | 一个实体 | Element, ProcessingInstruction, Comment, Text, CDATASection, Entity参考手册 |
7 | ProcessingInstruction | 一个处理指令 | None |
8 | Comment | 一个注释 | None |
9 | Document | 整个文档(DOM树的根节点) | Element, ProcessingInstruction, Comment, DocumentType |
10 | DocumentType | 为文档实体提供接口 | None |
11 | DocumentFragment | 表示邻接节点和它们的子树。 | Element, ProcessingInstruction, Comment, Text, CDATASection, Entity参考手册 |
12 | Notation | 代表一个符号在DTD中的声明 | None |
Node Type - The return value s
Returns the value of the node name and node type of each node value of the property:
节点类型 | nodeName 返回值 | nodeValue 返回值 | |
---|---|---|---|
1 | Element | 元素名 | null |
2 | Attr | 属性名 | 属性值 |
3 | Text | #text | 节点内容 |
4 | CDATASection | #cdata-section | 节点内容 |
5 | Entity 参考手册 | 实体参考名 | null |
6 | Entity | 实体名 | null |
7 | ProcessingInstruction | target | 节点的内容 |
8 | Comment | #comment | 注释文本 |
9 | Document | #document | null |
10 | DocumentType | doctype name | null |
11 | DocumentFragment | #document fragment | null |
12 | Notation | 符号名称 | null |
Node Type - Static variable name
Node类型 | Named Constant |
---|---|
1 | ELEMENT_NODE |
2 | ATTRIBUTE_NODE |
3 | TEXT_NODE |
4 | CDATA_SECTION_NODE |
5 | ENTITY_REFERENCE_NODE |
6 | ENTITY_NODE |
7 | PROCESSING_INSTRUCTION_NODE |
8 | COMMENT_NODE |
9 | DOCUMENT_NODE |
10 | DOCUMENT_TYPE_NODE |
11 | DOCUMENT_FRAGMENT_NODE |
12 | NOTATION_NODE |