Latest web development tutorials

XML DOM item () method

NamedNodeMap Object Reference NamedNodeMap objects

Definition and Usage

item () method returns the index number of the specified node list node.

grammar

item(index)

参数 描述
index 索引。


Examples

The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc loop through <book> element and print category attribute values:

Examples

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.getElementsByTagName('book');

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

The code above will output:

COOKING
CHILDREN
WEB
WEB

try it"

Try Demos

item () - loop through items in a list node

getNamedItem () - change the value of an item


NamedNodeMap Object Reference NamedNodeMap objects