Name
HTMLCollection.item( ): get an element by position â DOM Level 2 HTML
Synopsis
Node item(unsigned longindex
);
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.
Returns
The element at the specified
index
, or null
if index
is less than zero or greater than or equal to the length
property.
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.
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
See Also
NodeList.item( )
Get JavaScript: The Definitive Guide, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.