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

XML DOM getAttributeNode() Method

XML DOM getAttributeNode() Method


Element Object Reference Element Object


Definition and Usage

The getAttributeNode() method retrieves an attribute node from the current element by name.

Syntax

elementNode.getAttributeNode(name)

Parameters Description
name Required. Specifies the attribute node to retrieve.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc, and from all elements, get the "category" attribute:

Example

xmlDoc

=

loadXMLDoc

(

"

books.xml

"

)

;

x

=

xmlDoc

.

getElementsByTagName

(

'

book

'

)

;

for

(

i

=

0

;

i

<

x

.

length

;

i

++

)

{

attnode

=

x

.

item

(

i

)

.

getAttributeNode

(

"

category

"

)

;

document

.

write

(

attnode

.

name

)

;

document

.

write

(

"

=

"

)

;

document

.

write

(

attnode

.

value

)

;

document

.

write

(

"


"

)

;

}

Output:

category = COOKING

category = CHILDREN

category = WEB

category = WEB

Try it »


Element Object Reference Element Object