Favorites

DOM Node.nodeType Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Node.nodeType
DOM Node PropertyThis property is supported by all modern browsers.
Updated 28th November 2026

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.nodeType

Value

A number identifying the kind of node, such as 1 for elements, 3 for text and 9 for the document.

Example

<p>Text</p>
const p = document.querySelector('p');
console.log(p.nodeType === Node.ELEMENT_NODE);
console.log(p.firstChild.nodeType === Node.TEXT_NODE);
console.log(document.nodeType);

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.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee