Instance
Gets the node type of the BODY element:
Document.body.nodeType;
Results:
1
Definition and usage
The NodeType property returns the node type that returns the specified node as a numeric value.
If the node is an element node, the NodeType property returns 1.
If the node is an attribute node, the NodeType property returns 2.
Browser support
IE |
Firefox |
Chrome |
Safari |
Opera |
√ |
√ |
√ |
√ |
√ |
NodeType properties are supported in all major browsers.
Grammar
Node.nodetype
Technical details
return value: |
A string value that represents the node type of the node. |
DOM version |
Core Level 1 Node Object |
Node Types
Documents, elements, attributes, and other aspects of the HTML or XML document have different node types.
There are 12 different node types, which may have child nodes of different node types:
node Type |
Description |
child Nodes |
1 |
Element |
Represents an Element |
Element, Text, Comment, ProcessingInstruction, Cdatasection, EntityReference |
2 |
Attr |
Represents a property |
Text, EntityReference |
3 |
Text |
Represents the text content in an element or attribute. |
None |
4 |
Cdatasection |
Represents a CDATA section in a document (text that is not parsed by the parser). |
None |
5 |
EntityReference |
Represents an entity reference. |
Element, ProcessingInstruction, Comment, Text, Cdatasection, EntityReference |
6 |
Entity |
Represents an entity. |
Element, ProcessingInstruction, Comment, Text, Cdatasection, EntityReference |
7 |
ProcessingInstruction |
Represents a processing instruction. |
None |
8 |
Comment |
Represents a comment. |
None |
9 |
Document |
Represents the entire document (the root node of the DOM tree). |
Element, ProcessingInstruction, Comment, DocumentType |
10 |
DocumentType |
To provide an interface to an entity defined for a document |
None |
11 |
DocumentFragment |
Represents a lightweight document object that can hold a portion of a file |
Element, ProcessingInstruction, Comment, Text, Cdatasection, EntityReference |
12 |
Notation |
Represents the symbol declared in the DTD. |
None |
Node Type-return value
For each node type, the return value of the NodeName and NodeValue properties:
node Type |
NodeName return |
NodeValue return |
1 |
Element |
Element name |
Null |
2 |
Attr |
Property name |
Property value |
3 |
Text |
#text |
The contents of the node |
4 |
Cdatasection |
#cdata-section |
The contents of the node |
5 |
EntityReference |
Entity reference name |
Null |
6 |
Entity |
Entity Name |
Null |
7 |
ProcessingInstruction |
Target |
The contents of the node |
8 |
Comment |
#comment |
Comment Text |
9 |
Document |
#document |
Null |
10 |
DocumentType |
Document type name |
Null |
11 |
DocumentFragment |
#document fragments |
Null |
12 |
Notation |
Symbol name |
Null |
Nodetypes-named Constants
NodeType |
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 |
HTML DOM NodeType Properties