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

XML DOM getAttribute() Method

XML DOM getAttribute() Method


Element Object Reference Element Object


Definition and Usage

The getAttribute() method retrieves an attribute value by name.

Syntax

elementNode.getAttribute(name)

Parameters Description
name Required. Specifies the attribute from which to retrieve the value.

Example

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

Example

xmlDoc

=

loadXMLDoc

(

"

books.xml

"

)

;

x

=

xmlDoc

.

getElementsByTagName

(

'

book

'

)

;

for

(

i

=

0

;

i

<

x

.

length

;

i

++

)

{

document

.

write

(

x

[

i

]

.

getAttribute

(

'

category

'

)

)

;

document

.

write

(

"


"

)

;

}

Output:

COOKING

CHILDREN

WEB

WEB

Try it »


Element Object Reference Element Object