asp.net.ph

Skip Navigation Links

item Method

DHTML Methods


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.

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 );
}


© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note