item Method

Internet Development Index

Retrieves an attribute for an element from the attributes collection.

Syntax

oItem = attributes.item(vIndex)

Parameters

vIndex Required. Integer or String that specifies the attribute. If this parameter is an integer, it is the zero-based index of the attribute in the attributes collection. If this parameter is a string, the attribute whose name matches the string is retrieved.

Return Value

Returns an attribute if successful, otherwise null.

Remarks

This method returns an error if the attribute is not found. When retrieving an attribute by name, vIndex must match the case of the attribute.

Examples

This example uses the item method to retrieve the name and value of each attribute for an element and whether it has been specified.

<HTML>
<HEAD>
<SCRIPT>
function Init()
{
oAttrColl = oElem.attributes;
for (i = 0; i < oAttrColl.length; i++)
{
oAttr = oAttrColl.item(i);
bSpecified = oAttr.specified;
sName = oAttr.nodeName;
vValue = oAttr.nodeValue;
alert(sName + ": " + bSpecified + ": " + vValue);
}
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="Init()">
<P ID="oElem">An element.</P>
</BODY>
</HTML>

Standards Information

This method is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 Non-Microsoft link.

Applies To

attributes