Easy Tutorial
❮ Dom Met Element Getattribute Dom Http ❯

XML DOM item() Method



Definition and Usage

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

Syntax

Parameter Description
index The index.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc, loops through the <book> elements, and prints the value of the category attribute:

Example

xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');

for(i=0;i&lt;x.length;i++)
{
  att=x.item(i).attributes.getNamedItem("category");
  document.write(att.value + "<br>");
}

The code above will output:


Try It

item() - Loop through items in a node list

getNamedItem() - Change the value of an item


❮ Dom Met Element Getattribute Dom Http ❯