Easy Tutorial
❮ Prop Document Childnodes Dom Prop Attr Value ❯

XML DOM getNamedItem() Method



Definition and Usage

The getNamedItem() method returns the specified node.

Syntax

Parameter Description
nodename The name of the node to retrieve.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc, iterates through <book> elements, and prints the value of the category attribute:

Example

xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');

for(i=0;i&lt;x.length;i++)
{
  att=x.item(i).attributes.getNamedItem("category");
  document.write(att.value + "<br>");
}

The code above will output:


Try It Demos

getNamedItem() - Change the value of an item


❮ Prop Document Childnodes Dom Prop Attr Value ❯