XML DOM getAttribute() Method
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
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