Easy Tutorial
❮ Met Element Replacechild Met Nodemap Item ❯

XML DOM getAttribute() Method


Definition and Usage

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

Syntax

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

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc and retrieves the value of the "category" attribute from 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:

❮ Met Element Replacechild Met Nodemap Item ❯