W3cubDocs

/DOM

HTMLCollection.item

HTMLCollection.item() gets an element by position.

Parameters

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

Return value

The Node 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

© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection/item