This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

attribute

Property of dom/HTMLElementdom/HTMLElement

Syntax

var result = element.attribute;
element.attribute = value;

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>

Notes

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 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.

Syntax

Standards information

See also

Related pages

  • About the W3C Document Object Model

Attributions