Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM attributes Property

XML DOM attributes Property


Element Object Reference Element Object


Definition and Usage

The attributes property returns a NamedNodeMap containing the attributes of the selected node.

If the selected node is not an element, this property returns NULL.

Syntax

elementNode.attributes


Tips and Notes

**Tip:** This property is for element nodes only.


Example 1

The following code snippet uses loadXMLDoc() to load "books.xml" Load into xmlDoc, and get the number of attributes of the first element in "books.xml": </p>

Example

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.getElementsByTagName("book")[0].attributes;

document.write(x.length);

The code above will output:

1

Try it »


Example 2

The following code snippet uses loadXMLDoc() to load "books.xml" Load into xmlDoc, and get the value of the "category" attribute of the first element:

Example

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.getElementsByTagName("book")[0].attributes;

att=x.getNamedItem("category");

document.write(att.value);

The code above will output:

COOKING

Try it »


Element Object Reference Element Object