Latest web development tutorials

XML DOM getAttribute () method

Element Object Reference Element object

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>");
}

Output:

COOKING
CHILDREN
WEB
WEB

try it"

Element Object Reference Element object