2 out of 3 rated this helpful - Rate this topic

attributes property

[This documentation is preliminary and is subject to change.]

Retrieves the collection of attributes belonging to the object.

Document Object Model (DOM) Level 3 Core Specification, Section 1.4

Syntax

JavaScript

p = object.attributes

Property values

Type: IDispatch

Zero-based array of attributes applied to the object.

Standards information

Remarks

The attributes collection does not expose the style object. Use the cssText property of the object's style property to retrieve the persistent representation of the cascading styles associated with an object.

Unlike other DHTML collections, such as all and children, the attributes collection is static. Modifications to the properties of an object are not automatically reflected by an existing reference to the attributes collection of that object.

In Microsoft Internet Explorer 6, this collection now applies to the attribute object.

The expando properties of an object are included in the attributes collection of the object as of Internet Explorer 6. To access the expando properties of an object in earlier versions of Windows Internet Explorer, use the Microsoft JScript for...in construct.

Examples

This example shows how to iterate through the collection of attributes of the specified object, displaying the name and value of the attributes as well as the language of the attribute (HTML or script).


<SCRIPT>
function ShowAttribs(oElem)
{
    txtAttribs.innerHTML = '';
    // Retrieve the collection of attributes for the specified object.
    var oAttribs = oElem.attributes;
    // Iterate through the collection.
    for (var i = 0; i < oAttribs.length; i++)
    {
        var oAttrib = oAttribs[i];
        // Print the name and value of the attribute. 
        // Additionally print whether or not the attribute was specified
        // in HTML or script.
        txtAttribs.innerHTML += oAttrib.nodeName + '=' + 
            oAttrib.nodeValue + ' (' + oAttrib.specified + ')<BR>'; 
    }
}
</SCRIPT>

See also

About the W3C Document Object Model

 

 

Build date: 3/8/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
caution - weird object, not array
N.B. oDIV.attributes is actually an [object] with length-- but not an array: despite definitions:

It is-not in the context of array.methods()--

neg.
[0].concat(oDIV.attributes) // returns "0,[object]" instead of "0,id#1,id#2,..."