The getAttribute() method gets an attribute value by name.
elementNode.getAttribute(name)
The following code fragment loads "books.xml" into xmlDoc using loadXMLDoc() and gets the value of the "category" attribute in all <book> elements:
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
getAttribute() - Get a specified attribute's value
Jump to: Top of Page or HOME or Printer friendly page
W3Schools provides material for training only. We do not warrant the correctness of its contents. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright 1999-2008 by Refsnes Data. All Rights Reserved.