Skip to content

XML DOM Node Information

How to access and understand XML DOM node properties like nodeName, nodeValue, and nodeType in JavaScript for element, text, and attribute nodes.

The nodeName, nodeValue, and nodeType properties contain information about nodes.

Node Properties

Objects have methods and properties, that can be accessed and manipulated by JavaScript.

Three important node properties are:

  • nodeName
  • nodeValue
  • nodeType

The nodeName Property

The nodeName property specifies the name of a node.

More in detail:

  • nodeName is read-only
  • nodeName of an element node is the same as the tag name
  • nodeName of an attribute node is the attribute name
  • nodeName of a text node is always #text
  • nodeName of the document node is always #document

The nodeValue Property

The nodeValue property specifies the value of a node.

More in detail:

  • nodeValue for element nodes is undefined
  • nodeValue for text nodes is the text itself
  • nodeValue for attribute nodes is the attribute value

The nodeType Property

The nodeType property specifies the type of node.

NodeType 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
Navigation