In practical application the
name and
index arguments will almost never be the same value. To look up an HTML element by name you are likely to need a modification to the sample code like this:
_variant_t name = "NameOfElement"; // or zero-based index in the IHTMLElementCollection
_variant_t index = 0l;
hResult = ppvSelect->item( name, index, &ppvdispOption );
if FAILED(hResult) return(hResult);
This assumes each element on the document has a unique name - a likely scenario. But if you have more than one element with the same name this might not be the right solution for you. In that case the
index is "
the zero-based index of the object to retrieve when a collection is returned." So keep this in mind if you don't get back the element you were looking for as there might be more than one with the same name.