XML DOM getElementsByTagName()Methods
Element object
Definition and Usage
The getElementsByTagName() method returns a NodeList of all elements with the specified name.
Syntax
getElementsByTagName(name)
| Parameter | Description |
|---|---|
| name | String, specifies the tag name to search for. The value "*" matches all tags. |
Example
The following code snippet usesloadXMLDoc()put "books.xmlLoad into xmlDoc and retrieve the values of all <title> elements:
Example
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('title');
for (i=0;i<x.length;i++)
{
document.write(x[i].childNodes[0].nodeValue);
document.write("
");
}
x=xmlDoc.getElementsByTagName('title');
for (i=0;i<x.length;i++)
{
document.write(x[i].childNodes[0].nodeValue);
document.write("
");
}
Output:
Everyday Italian
Harry Potter
XQuery Kick Start
Learning XML
Harry Potter
XQuery Kick Start
Learning XML
Try it Yourself »
Element objectother extensions