XML DOM item() Method

NamedNodeMap Object Reference Manual

Definition and Usage

The item() method can return the node in the node list at the specified index.

Syntax:

item(index)
Parameter Description
index Index Number

Example

In all examples, we will use the XML file books.xml, and JavaScript function loadXMLDoc().

The following code snippet can loop through <book> elements and output the value of the category attribute:

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
  {
  var att=x.item(i).attributes.getNamedItem("category");
  document.write(att.value + "<br />")
  }

Output:

COOKING
CHILDREN
WEB
WEB

NamedNodeMap Object Reference Manual