XML DOM item() method
Definition and usage
The item() method returns the node at the specified index position.
Syntax:
htmlcollectionObject.item(index)
Parameter | Description |
---|---|
index |
Required. The index position of the node to be returned. This value is an integer greater than 0 and less than or equal to HTMLCollection.length-1. The order of nodes or elements in the HTMLCollection object is the same as their order in the document source code. |
Return value
Returns specified index The element or node at the position. index Returns null if less than 0 or greater than the length property.
Description
In JavaScript, it is easier to treat HTMLCollection as an array and index it using array syntax.
Example
var c = document.images; //This is an HTMLCollection object var img0 = c.item(0); //The item() method can be used in this way var img1 = c.[1]; //This notation is easier and more common
Related pages
XML DOM reference manual:NodeList.item()