item Method
Retrieves an object or a collection from the specified collection.
Syntax
vItem = object.item(vIndex [, iSubIndex])
Parameters
vIndex Required. Variant that specifies the number or string that indicates the object or collection to retrieve. If this parameter is a number, the method returns the object in the collection at the given position, where the first object has value 0, the second has 1, and so on. If this parameter is a string and there is more than one object with the name or id properties equal to the string, the method returns a collection of matching objects. iSubindex Optional. Integer that specifies the position of an object to retrieve. This parameter is used when vIndex is a string. The method uses the string to construct a collection of all objects that have a name or id equal to the string, and then retrieves from this collection the object at the position specified by iSubIndex.
Return Value
Variant. Returns an object or a collection of objects if successful, or null otherwise.
Remarks
The TextRectangle, attributes, and rules collections only accept an integer value for the vIndex parameter.
Example
This example uses the item method to retrieve each object from the document. In this case, the method parameter is a number, so the objects are retrieved in the order in which they appear in the document.
Sample Code
<SCRIPT LANGUAGE="JScript"> var coll = document.all; if (coll!=null) { for (i=0; i<coll.length; i++) alert(coll.item(i).tagName); } </SCRIPT>This example uses the item method to retrieve a collection of all objects in the document having "Sample" as an id. It then uses item again to retrieve each object from the "Sample" collection.
<SCRIPT LANGUAGE="JScript"> var coll = document.all.item("Sample"); If (coll != null) { for (i=0; i<coll.length; i++) { alert(coll.item(i).tagName); } } </SCRIPT>This example is similar to the previous example, but uses the optional iSubindex parameter of item to retrieve individual objects.
<SCRIPT LANGUAGE="JScript"> var coll = document.all.item("Sample") if (coll!=null) { for (i=0; i<coll.length; i++) alert(document.all.item("Sample",i).tagName); } </SCRIPT>
Applies To
[ Object Name ] Platform Version Win16: Win32: Mac: Unix: WinCE: Version data is listed when the mouse hovers over a link, or the link has focus. all, anchors, applets, areas, attributes, behaviorUrns, bookmarks, boundElements, cells, childNodes, children, controlRange, elements, embeds, filters, forms, frames, images, imports, links, options, plugins, rows, rules, scripts, styleSheets, tbodies, TextRectangle
Did you find this topic useful? Suggestions for other topics? write us!
© 1999 microsoft corporation. all rights reserved. terms of use.