Microsoft HomeproductssearchsupportshopWrite Us   Microsoft Home
Magazine
 |  Community
 |  Workshop
 |  Tools & Samples
 |  Training
 |  Site Info

Workshop  |  DHTML, HTML & CSS

item Method


Retrieves an element or a collection from the given collection depending on the vIndex parameter.

Syntax

oElement = object.item(vIndex [, iSubIndex] )

Parameters

vIndexRequired. 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.
iSubIndexOptional. 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


Does this content meet your programming needs? Write us!

Back to topBack to top

© 1998 Microsoft Corporation. All rights reserved. Terms of use.

 

Magazine Home
Ask Jane
DHTML Dude
Extreme XML
For Starters
More or Hess
Servin' It Up
Site Lights
Web Men Talking
Member Community Home
Benefits: Freebies & Discounts
Benefits: Promote Your Site
Benefits: Connect with Your Peers
Benefits at a Glance
Online Special-Interest Groups
Your Membership
SBN Stores
Join Now
Workshop Home
Essentials
Content & Component Delivery
Component Development
Data Access & Databases
Design
DHTML, HTML & CSS
Extensible Markup Language (XML)
Languages & Development Tools
Messaging & Collaboration
Networking, Protocols & Data Formats
Reusing Browser Technology
Security & Cryptography
Server Technologies
Streaming & Interactive Media
Web Content Management
Workshop Index
Tools & Samples Home
Tools
Samples, Headers, Libs
Images
Sounds
Style Sheets
Web Fonts
Training Home
SBN Live Seminars
SBN Live Chats
Courses
Peer Support
CD-ROM Training
Books & Training Kits
Certification
SBN Home
New to SBN?
What's New on SBN
Site Map
Site Search
Glossary
Write Us
About This Site