Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM item() Method

XML DOM item() Method


NamedNodeMap Object Reference NamedNodeMap object


Definition and Usage

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

Syntax

item(index)

Parameters Description
index Index.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" Load into xmlDoc, loop through the elements and print the value of the category attribute:

Example

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 it

item() - Loop through the items in a node list

getNamedItem() - Change the value of an item


NamedNodeMap Object Reference NamedNodeMap object