Magazine |
| | Community |
| | Workshop |
| | Tools & Samples |
| | Training |
| | Site Info |
|
|
||||||||
|
Retrieves an element or a collection from the given collection depending on the vIndex parameter.
Syntax
oElement = object.item(vIndex [, iSubIndex] )
Parameters
vIndex Required. Number or string specifying the element or collection to retrieve. If this parameter is a number, the method returns the element in the collection at the given position, where the first element has value 0, the second has 1, and so on. If this parameter is a string and there is more than one element with the name or id property equal to the string, the method returns a collection of matching elements. iSubIndex Optional. Position of an element to retrieve. This parameter is used when vIndex is a string. The method uses the string to construct a collection of all elements that have a name or id equal to the string and then retrieves from this collection the element at the position specified by iSubIndex.
Return Value
Returns an element object or a collection of element objects if successful, or null otherwise.
Remarks
The textRectangle, and attributes collections only accept an integer value for the vIndex parameter.
Example
The following JScript (compatible with ECMA 262 language specification) example uses the item method to retrieve each element from the document. In this case, the method parameter is a number, so the elements are retrieved in the order in which they appear in the document.
Sample Code
var coll = document.all; if (coll!=null) { for (i=0; i<coll.length; i++) alert(coll.item(i).tagName); }The following JScript example uses the itemmethod to retrieve a collection of all elements in the document having "Sample" as an id. It then uses item again to retrieve each element from the "Sample" collection.
var coll = document.all.item("Sample"); If (coll != null) { for (i=0; i<coll.length; i++) { alert(coll.item(i).tagName); } }The following JScript example is similar to the previous example but uses the optional subindex parameter of item to retrieve individual elements.
var coll = document.all.item("Sample") if (coll!=null) { for (i=0; i<coll.length; i++) alert(document.all.item("Sample",i).tagName); }
Applies To
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
Does this content meet your programming needs? Write us!
© 1998 Microsoft Corporation. All rights reserved. Terms of use.