XML DOM getAttributeNode()Methods
Element object
Definition and Usage
The getAttributeNode() method retrieves the attribute node from the current element by name.
Syntax
elementNode.getAttributeNode(name)
| Parameter | Description |
|---|---|
| name | Required. Specifies the attribute node to retrieve. |
Example
The following code snippet usesloadXMLDoc()put "books.xmlLoad it into xmlDoc, and retrieve the "category" attribute from all the <book> elements:
Example
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
attnode=x.item(i).getAttributeNode("category");
document.write(attnode.name);
document.write(" = ");
document.write(attnode.value);
document.write("<br>");
}
Output:
category = COOKING
category = CHILDREN
category = WEB
category = WEB
category = CHILDREN
category = WEB
category = WEB
Try it Yourself »
Element objectother extensions