DOM Node.nodeType Property
The nodeType property returns a number that tells you what kind of node something is, such as 1 for an element or 3 for text.
Description
The read-only nodeType property is an integer identifying the type of node. The common values are Node.ELEMENT_NODE (1), Node.TEXT_NODE (3), Node.COMMENT_NODE (8), Node.DOCUMENT_NODE (9) and Node.DOCUMENT_FRAGMENT_NODE (11). Compare against the named constants for readability.
Other node types include Node.DOCUMENT_TYPE_NODE (10) for the doctype, Node.PROCESSING_INSTRUCTION_NODE (7) and Node.CDATA_SECTION_NODE (4), which mostly appear in XML documents. The nodeName property gives a readable name instead, such as "#text" for text nodes or the tag name for elements.
Checking nodeType is common when walking the DOM tree, such as when collecting only the text nodes inside an element. For elements, instanceof Element or instanceof HTMLElement also works.
Syntax
node.nodeTypeValue
A number identifying the kind of node, such as 1 for elements, 3 for text and 9 for the document.
Example
Browser Support
The following information will show you the current browser support for the Node.nodeType property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





