{} {} ApiRef
Abstract
Returns a code (integer) representing the type of node.
Syntax
Type = node .nodeType
Type
is a short unsigned integer with the following values:
- Node.ELEMENT_NODE == 1 ( element node )
- Node.ATTRIBUTE_NODE == 2 ( node attribute )
- Node.TEXT_NODE == 3 ( text node )
- Node.CDATA_SECTION_NODE == 4 ( CDATA section node )
- Node.ENTITY_REFERENCE_NODE == 5 ( node reference to an entity )
- Node.ENTITY_NODE == 6 ( Feature node )
- Node.PROCESSING_INSTRUCTION_NODE == 7 ( processing instruction node )
- Node.COMMENT_NODE == 8 ( comment node )
- Node.DOCUMENT_NODE == 9 ( document node )
- Node.DOCUMENT_TYPE_NODE == 10 ( Document Type node )
- Node.DOCUMENT_FRAGMENT_NODE == 11 ( node document fragment )
- Node.NOTATION_NODE == 12 ( node notation )
Example
This example checks if the first node inside the document element is a comment node, and if this is not the case, displays a message.
var node = document.documentElement.firstChild; if (node.nodeType! = Node.COMMENT_NODE) alert ("Your code should be well commented.");
Specification
- Reference DOM Level 2 Core: nodeType
- Reference DOM Level 3 Core: nodeType
- Translation French DOM Level 2: nodeType (non-normative)
Étiquettes et contributeurs liés au document
Dernière mise à jour par :
arunpandianp,