element.nodeType

{} {} ApiRef

Abstract

Returns a code (integer) representing the type of node.

Syntax

Type = node .nodeType

Type is a short unsigned integer with the following values:

  • Node.ELEMENT_NODE == 1 ( element node )
  • Node.ATTRIBUTE_NODE == 2 ( node attribute )
  • Node.TEXT_NODE == 3 ( text node )
  • Node.CDATA_SECTION_NODE == 4 ( CDATA section node )
  • Node.ENTITY_REFERENCE_NODE == 5 ( node reference to an entity )
  • Node.ENTITY_NODE == 6 ( Feature node )
  • Node.PROCESSING_INSTRUCTION_NODE == 7 ( processing instruction node )
  • Node.COMMENT_NODE == 8 ( comment node )
  • Node.DOCUMENT_NODE == 9 ( document node )
  • Node.DOCUMENT_TYPE_NODE == 10 ( Document Type node )
  • Node.DOCUMENT_FRAGMENT_NODE == 11 ( node document fragment )
  • Node.NOTATION_NODE == 12 ( node notation )

Example

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

var node = document.documentElement.firstChild;

if (node.nodeType! = Node.COMMENT_NODE)
  alert ("Your code should be well commented.");

Specification

Étiquettes et contributeurs liés au document

Étiquettes : 
Contributeurs à cette page : fscholz, teoli, arunpandianp, ethertank, Mgjbot, Takenbot, BenoitL
Dernière mise à jour par : arunpandianp,