Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The read-only nodeType property of a Node interface is an integer that identifies what the node is. It distinguishes different kinds of nodes from each other, such as elements, text, and comments.
An integer which specifies the type of the node. Possible values are:
Node.ELEMENT_NODE (1)An Element node like <p> or <div>.
Node.ATTRIBUTE_NODE (2) Node.TEXT_NODE (3)The actual Text inside an Element or Attr.
Node.CDATA_SECTION_NODE (4)A CDATASection, such as <!CDATA[[ … ]]>
Node.PROCESSING_INSTRUCTION_NODE (7)A ProcessingInstruction of an XML document, such as <?xml-stylesheet … ?>.
Node.COMMENT_NODE (8)A Comment node, such as <!-- … -->.
Node.DOCUMENT_NODE (9)A Document node.
Node.DOCUMENT_TYPE_NODE (10)A DocumentType node, such as <!doctype html>.
Node.DOCUMENT_FRAGMENT_NODE (11)A DocumentFragment node.
The following constants have been deprecated and are not in use anymore: Node.ENTITY_REFERENCE_NODE (5), Node.ENTITY_NODE (6), and Node.NOTATION_NODE (12).
This example checks if the first node inside the document element is a comment, and displays a message if not.
| DOM # ref-for-dom-node-nodetype① |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Oct 26, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.