XML DOM getAttribute () method
Definition and Usage
getAttribute () method to obtain the attribute value by name.
grammar
elementNode.getAttribute(name)
参数 | 描述 |
---|---|
name | 必需。规定从中获取属性值的属性。 |
Examples
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc and obtain value "category" attribute of all <book> element:
Examples
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
for (i=0;i<x.length;i++)
{
document.write(x[i].getAttribute('category'));
document.write("<br>");
}
x=xmlDoc.getElementsByTagName('book');
for (i=0;i<x.length;i++)
{
document.write(x[i].getAttribute('category'));
document.write("<br>");
}
Output:
COOKING
CHILDREN
WEB
WEB
CHILDREN
WEB
WEB
try it"
Element object