XML DOM » Node » nodeName

Syntax:
node.nodeName

This property is read-only and contains the name of the node, depending on type.

The nodeName property is read-only and contains the name of the node, depending on type. This name is a string value and is never empty. The various types of name returned by each node are detailed below.

Examples

Code:
XML:

<States>
   <State ref="FL">
      <name>Florida</name>
      <capital>Tallahassee</capital>
   </State>
   <State ref="IA">
      <name>Iowa</name>
      <capital>Des Moines</capital>
   </State>
</States>

JavaScript:

var xml_doc = new
ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("states.xml");

var n = xml_doc;
document.write(n.nodeName);
n = xml_doc.documentElement;
document.write("<br>" + n.nodeName);
Output:
#document
States
Explanation:

This example uses the 'states.xml' file and obtains the node names of the document itself, and of the document's root node.

Language(s): JavaScript XML