YouTip LogoYouTip

Prop Node Nodetype

Element Object ## Example Return the node type of the body element: document.body.nodeType; Output: 1 [Try it Β»]( * * * ## Definition and Usage The nodeType property returns the node type. If the node is an element node, the nodeType property returns 1. If the node is an attribute node, the nodeType property returns 2. If the node is a text node, the nodeType property returns 3. If the node is a comment node, the nodeType property returns 8. This property is read-only. * * * ## Browser Support All major browsers support the nodeType property * * * ## Syntax _node_.nodeType ## Technical Details | Return Value: | A String, representing the node type of the node. | | --- | | DOM Version | Core Level 1 Node Object | * * * ## ( The document, elements, attributes, etc., of an HTML or XML document have different node types. There are 12 different node types, and different node types can also have different child node types: | Node Type | Description | Child Nodes | | --- | --- | --- | | 1 | Element | An element | Element, Text, Comment, ProcessingInstruction, CDATASection, Entity Reference | | 2 | Attr | An attribute | Text, Entity Reference | | 3 | Text | The textual content of an element or attribute | None | | 4 | CDATASection | A CDATA section of a document (text will not be parsed by the parser) | None | | 5 | Entity Reference | Entity reference | Element, ProcessingInstruction, Comment, Text, CDATASection, Entity Reference | | 6 | Entity | An entity | Element, ProcessingInstruction, Comment, Text, CDATASection, Entity Reference | | 7 | ProcessingInstruction | A processing instruction | None | | 8 | Comment | A comment | None | | 9 | Document | The entire document (root node of the DOM tree) | Element, ProcessingInstruction, Comment, DocumentType | | 10 | DocumentType | Provides an interface to the entities of a document | None | | 11 | DocumentFragment | Represents adjacent nodes and their subtrees. | Element, ProcessingInstruction, Comment, Text, CDATASection, Entity Reference | | 12 | Notation | Represents a notation declared in the DTD | None | ## Node Types - Return Values Return the node name and the value of the nodeValue property for each node type: | Node Type | nodeName Return Value | nodeValue Return Value | | --- | --- | --- | | 1 | Element | Element name | null | | 2 | Attr | Attribute name | Attribute value | | 3 | Text | #text | Node content | | 4 | CDATASection | #cdata-section | Node content | | 5 | Entity Reference | Entity reference name | null | | 6 | Entity | Entity name | null | | 7 | ProcessingInstruction | target | Node content | | 8 | Comment | #comment | Comment text | | 9 | Document | #document | null | | 10 | DocumentType | doctype name | null | | 11 | DocumentFragment | #document fragment | null | | 12 | Notation | Notation name | null | ## Node Types - Static Variable Names | Node Type | Named Constant | | --- | --- | | 1 | ELEMENT_NODE | | 2 | ATTRIBUTE_NODE | | 3 | TEXT_NODE | | 4 | CDATA_SECTION_NODE | | 5 | ENTITY_REFERENCE_NODE | | 6 | ENTITY_NODE | | 7 | PROCESSING_INSTRUCTION_NODE | | 8 | COMMENT_NODE | | 9 | DOCUMENT_NODE | | 10 | DOCUMENT_TYPE_NODE | | 11 | DOCUMENT_FRAGMENT_NODE | | 12 | NOTATION_NODE | * * * Element Object
← Prop Node NodevalueProp Node Nodename β†’