Latest web development tutorials

XML DOM attributes property

Element Object Reference Element object

Definition and Usage

attributes property returns the node that contains the selected property NamedNodeMap.

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

grammar

elementNode.attributes


Tips and Notes

Note: This attribute is used only element nodes.


Example 1

The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc and obtain property "books.xml" the first <title> element number:

Examples

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 fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc, and made the first <book> value "category" attribute of the element:

Examples

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