www.fgks.org   »   [go: up one dir, main page]

Click to Rate and Give Feedback
Methods
 item Method
item Method

Gets 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 to be retrieved from 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 the item method gets an attribute by name, vIndex must match the case of the attribute.

Examples

This example uses the item method to get the name and value of each attribute for an element, and to determine whether the attribute 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 >
<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 World Wide Web link.

Applies To

attributes
Tags What's this?: Add a tag
Community Content
 
Add Community Content
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker
DCSIMG