Contents Index Topic Contents | ||
Previous Topic: isSubscribed Next Topic: javaEnabled |
item
Description
Retrieves an element or a collection from the given collection. The index determines which action to take.
Syntax
element = object.item(index [, subindex])
Parameter Description index 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, the method returns a collection of elements, where the value of the name or id property for each element is equal to the string. subindex Optional. Number specifying the position of an element to retrieve. This parameter is used when index 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, then retrieves from this collection the element at the position specified by subindex. Return Value
Returns an element object or a collection of element objects if successful, or null otherwise.
Examples
The following JScript 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.
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 item method 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, cells, elements, embeds, filters, forms, frames, images, imports, links, options, plugins, rows, scripts, styleSheets
Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.