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); //Can use the item() method in this way var img1 = c.[1]; //But this notation is easier and more common
Related Pages
XML DOM Reference Manual:NodeList.item()