Section 25.145. HTMLCollection.item( ): get an element by position


25.145. HTMLCollection.item( ): get an element by position

DOM Level 2 HTML

25.145.1. Synopsis

 Node item(unsigned long index); 

25.145.1.1. Arguments

index

The position of the element to be returned. Elements appear in an HTMLCollection in the same order in which they appear in the document source.

25.145.1.2. Returns

The element at the specified index, or null if index is less than zero or greater than or equal to the length property.

25.145.2. Description

The item( ) method returns a numbered element from an HTMLCollection. In JavaScript, it is easier to treat the HTMLCollection as an array and to index it using array notation.

25.145.3. Example

 var c = document.images;  // This is an HTMLCollection var img0 = c.item(0);     // You can use the item( ) method this way var img1 = c[1];          // But this notation is easier and more common 

25.145.4. See Also

NodeList.item( )




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net