Attribute Object
Last Updated: 08-30-2005
Represents an element attribute in the Document Object Model (DOM).

name Retrieves the name of the Attribute.
ownerElement Retrieves the Element to which the Attribute belongs.
value Retrieves the value of the Attribute.

An attribute can be retrieved from an element node in three ways:
  • If you know the name of the attribute, you can retrieve its value using the getAttribute method.
  • If you know the local name and namespace URI of the attribute, you can retrieve its value using the getAttributeNS method.
  • If you want to access all attributes of an element, you can retrieve them using the attributes property. This property exposes a collection of zero or more Attribute objects. Each Attribute object expose a name and a value property.

The example below uses the following data.

<?xml version="1.0"?>
<?access-control allow="*"?>
<time hours="12" minutes="30" seconds="59" zone="pst" />

The following example iterates through the attributes collection of an XML element representing the time, and prints the name and value of each attribute in the collection to the debug log.

<vxml version="2.0">
   <data name="oTime" src="time.exml"/>
   <form id="main">
         // cache the root document element
         var oRoot = oTime.documentElement;
         // cache the root doc element's attributes collection
         var oAttrs = oRoot.attributes;
         // cache the count of attribute
         var iAttrs = oRoot.attributes.length;
         // iterate through the collection
         for (var i = 0; i < iAttrs; i++)
            // cache the attribute
            var oAttr = oAttrs.item(i);
            // log the name/value
            vxmllog( + "=" + oAttr.value);

[24]7 Inc.| Terms of Service| Privacy Policy| General Disclaimers