The HTMLCollection
method item()
returns the node located at the specified offset into the collection.
Note: Because the contents of an HTMLCollection
are live, changes to the underlying DOM can and will cause the position of individual nodes in the collection to change, so the index value will not necessarily remain constant for a given node.
The Node
at the specified index, or null
if index
is less than zero or greater than or equal to the length property.
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. See the example below.
var c = document.images;
var img0 = c.item(0);
var img1 = c[1];