Node.nodeType

  • Revision slug: DOM/Node.nodeType
  • Revision title: Node.nodeType
  • Revision id: 10250
  • Created:
  • Creator: Matej Lednar
  • Is current revision? No
  • Comment Reverted to earlier version; 27 words removed

Revision Content

{{ DomRef() }}

Summary

Returns an integer code representing the type of the node.

Syntax

var type = node.nodeType;

type is an unsigned short with one of the following values:

  • Node.ELEMENT_NODE == 1
  • Node.ATTRIBUTE_NODE == 2
  • Node.TEXT_NODE == 3
  • Node.CDATA_SECTION_NODE == 4
  • Node.ENTITY_REFERENCE_NODE == 5
  • Node.ENTITY_NODE == 6
  • Node.PROCESSING_INSTRUCTION_NODE == 7
  • Node.COMMENT_NODE == 8
  • Node.DOCUMENT_NODE == 9
  • Node.DOCUMENT_TYPE_NODE == 10
  • Node.DOCUMENT_FRAGMENT_NODE == 11
  • Node.NOTATION_NODE == 12

Example

This example checks if the first node inside the document element is a comment node, and if it is not, displays a message.

var node = document.documentElement.firstChild;
if(node.nodeType != Node.COMMENT_NODE)
  alert("You should comment your code well!");

Specification

DOM Level 2 Core: Node.nodeType

{{ languages( { "fr": "fr/DOM/element.nodeType", "it": "it/DOM/element.nodeType", "ja": "ja/DOM/element.nodeType", "pl": "pl/DOM/element.nodeType" } ) }}

Revision Source

<p>{{ DomRef() }}</p>
<h3 name="Summary">Summary</h3>
<p>Returns an integer code representing the type of the node.</p>
<h3 name="Syntax">Syntax</h3>
<pre class="eval"><em>var type</em> = <em>node</em>.nodeType;
</pre>
<p><code>type</code> is an unsigned short with one of the following values:</p>
<ul> <li>Node.ELEMENT_NODE == 1</li> <li>Node.ATTRIBUTE_NODE == 2</li> <li>Node.TEXT_NODE == 3</li> <li>Node.CDATA_SECTION_NODE == 4</li> <li>Node.ENTITY_REFERENCE_NODE == 5</li> <li>Node.ENTITY_NODE == 6</li> <li>Node.PROCESSING_INSTRUCTION_NODE == 7</li> <li>Node.COMMENT_NODE == 8</li> <li>Node.DOCUMENT_NODE == 9</li> <li>Node.DOCUMENT_TYPE_NODE == 10</li> <li>Node.DOCUMENT_FRAGMENT_NODE == 11</li> <li>Node.NOTATION_NODE == 12</li>
</ul>
<h3 name="Example">Example</h3>
<p>This example checks if the first node inside the document element is a comment node, and if it is not, displays a message.</p>
<pre class="eval">var node = document.documentElement.firstChild;
if(node.nodeType != Node.COMMENT_NODE)
  alert("You should comment your code well!");
</pre>
<h3 name="Specification">Specification</h3>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-111237558">DOM Level 2 Core: Node.nodeType</a></p> <p>{{ languages( { "fr": "fr/DOM/element.nodeType", "it": "it/DOM/element.nodeType", "ja": "ja/DOM/element.nodeType", "pl": "pl/DOM/element.nodeType" } ) }}</p>
Revert to this revision