XML DOM getAttribute()Methods


Element object

Definition and Usage

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

Syntax

elementNode.getAttribute(name)

Parameter Description
name Required. Specifies the attribute from which to obtain the attribute value.


Example

The code snippet below usesloadXMLDoc()put "books.xmlLoad into xmlDoc, and get the value of the "category" attribute from all <book> elements:

Example

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 Yourself »

Element objectother extensions