Attributes Object
Last Updated: 08-26-2005
Represents a collection of attribute objects in the Document Object Model (DOM).

Properties
length Retrieves the number of elements in the collection.

Methods
getNamedItem Retrieves from an Attributes collection the attribute with the specified nodeName.
getNamedItemNS Retrieves from an Attributes collection the attribute with the specified local name and namespace URI.
item Retrieves an object from the collection by its index.

Remarks
An Attributes object is returned by the attributes property of an Element node, that is, a Node object whose nodeType is Node.ELEMENT_NODE.
Individual attributes can be retrieved from an Attributes collection in three ways:
  • If you know the name of an attribute in the Attributes collection, you can retrieve that attribute using the getNamedItem method.
  • If you know the local name and namespace URI of an attribute in the Attributes collection, you can retrieve that attribute using the getNamedItemNS method.
  • All the attributes in the Attributes collection are accessible via an integral index, starting from 0, using the item method.
Examples

The example below uses the following data.

<?xml version="1.0"?>
<?access-control allow="*"?>
<date month="10" day="28" year="2005" />

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

<vxml version="2.1">
   <data name="oDate" src="date.exml"/>
   <form id="main">
      <script>
      <![CDATA[
         // cache the root document element
         var oRoot = oDate.documentElement;
         // cache the root doc element's attributes collection
         var oAttrs = oRoot.attributes;
         // cache the number of attributes
         var iAttrs = oAttrs.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.name + "=" + oAttr.value);
         }
       ]]>
       </script>
   </form>
</vxml>


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