Share via


item method

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

Retrieves an attribute for an element from an attributes collection.

Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5

Syntax

IDispatch retVal = object.item(name);

Standards information

Parameters

  • name [in]
    Type: VARIANT

    A pointer to a VARIANT of type VT_I4 or VT_BSTR 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.

Remarks

Call QueryInterface on pdisp to obtain an IHTMLDOMAttribute interface pointer.

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

Windows Internet Explorer 8 and later. In IE8 Standards mode, this method no longer indexes the attributes collection by the name property of the attribute object; it now accepts only numeric indexes or quoted numeric indexes. If given a string that is not a numeric index, this method will return the object at index 0. Use getNamedItem to reference an attribute by name. For more information, see Defining Document Compatibility.

Examples

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

IHTMLDOMNode* pElemDN;
IDispatch* pACDisp;
IHTMLAttributeCollection* pAttrColl;
IDispatch* pItemDisp;
IHTMLDOMAttribute* pItem;
LONG lACLength;
VARIANT vACIndex;
BSTR bstrName;
VARIANT vValue;
VARIANT_BOOL vbSpecified;
m_pElem->QueryInterface(IID_IHTMLDOMNode, (void**)&pElemDN);
pElemDN->get_attributes(&pACDisp);
pACDisp->QueryInterface(IID_IHTMLAttributeCollection, (void**)&pAttrColl);
pAttrColl->get_length(&lACLength);
vACIndex.vt = VT_I4;
for (int i = 0; i < lACLength; i++)
{
    vACIndex.lVal = i;
    pAttrColl->item(&vACIndex, &pItemDisp);
    pItemDisp->QueryInterface(IID_IHTMLDOMAttribute, (void**)&pItem);
    pItem->get_specified(&vbSpecified);
    pItem->get_nodeName(&bstrName);
    pItem->get_nodeValue(&vValue);
    pItemDisp->Release();
    pItem->Release();
}
pElemDN->Release();
pACDisp->Release();
pAttrColl->Release();

 

 

Build date: 1/26/2012