javascript Node nodeType

nodeType NN 6 IE 5 DOM 1  

 

Read-only  

Returns an integer that corresponds to a node type as specified in the W3C DOM. This is the preferred property to use to test a node object for its type (rather than the nodeName property values). Every node type has a value, but not all browsers that support the nodeType property support all node types as objects. The integer values have corresponding constants associated with them, which you can use to make more verbose, but easier-to-read script comparisons for node type processing (see the ATTRIBUTE_NODE property). Note that there is no way to distinguish element types (e.g., root Element node versus an HTMLElement node) via the nodeType property. Also note that IE 6 in Windows erroneously reports a DOCTYPE element as a comment node type.

 
Example
 
if (document.getElementById("elementID").firstChild.nodeType == 1) {
 // process as an element
}
 
Value

Integer values according to the following table.

 
Value Node type W3C DOM IE/Windows IE/Mac NN
1 ELEMENT_NODE 1 5 5 6
2 ATTRIBUTE_NODE 1 6 5 6
3 TEXT_NODE 1 5 5 6
4 CDATA_SECTION_NODE 1 n/a n/a n/a
5 ENTITY_REFERENCE_NODE 1 n/a n/a na/
6 ENTITY_NODE 1 n/a n/a n/a
7 PROCESSING_INSTRUCTION_NODE 1 n/a n/a n/a
8 COMMENT_NODE 1 6 5 6
9 DOCUMENT_NODE 1 5 5 6
10 DOCUMENT_TYPE_NODE 1 n/a n/a 6
11 DOCUMENT_FRAGMENT_NODE 1 n/a n/a 6
12 NOTATION_NODE 1 n/a n/a n/a
 
Default

Node-specific.


1332,Nickname,Homepage or email,Comments here,Add comment