The item() method is used to return the node at the specified index. The nodes are sorted as they appear in the source code. The index of the node list starts with 0.
Syntax:
nodelist.item( index )
or
nodelist[ index ]
Parameters: This method accepts single parameter index which is used to hold the index of node which need to return. It is required parameter and the index starts with 0.
Return Value: This method returns the node at specified index.
Example:
<!DOCTYPE html> <html> <head> <title> HTML DOM item() Method </title> <!-- script to change node value --> <script> function changeElement() { var gfg = document.getElementById("geeks"); gfg.getElementsByTagName("P")[1].innerHTML = "Welcome to GeeksforGeeks!"; } </script> </head> <body> <center> <div id="geeks"> <h1 style="color:green;">GeeksforGeeks</h1> <p>A computer science portal</p> <p>DOM item() Method</p> </div> <button onclick="changeElement()"> Click Here! </button> </center> </body> </html> |
Output:
Before Click on the button:

After Click on the button:

Supported Browsers: The browser supported by DOM item() Method are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTMLCollection item() Method
- CSSStyleDeclaration item() Method
- Program to Insert new item in array on any position in PHP
- How to make the cursor to hand when a user hovers over a list item using CSS?
- PHP program to add item at the beginning of associative array
- Get the first and last item in an array using JavaScript
- How to remove indentation from an unordered list item using CSS?
- How to insert an item into array at specific index in JavaScript?
- How to find if two arrays contain any common item in Javascript?
- JavaScript | Remove the last item from an array
- How to replace an item from an array in JavaScript?
- How to insert an item at the beginning of an array in PHP ?
- How to get the last item of JavaScript object ?
- PHP | DOMNamedNodeMap item() function
- PHP | DOMNodeList item() Function
- How to make whole area of a list item in navigation bar is clickable using CSS ?
- How to delete an item or object from the array using ng-click ?
- How to change the background color of the active nav-item?
- How to change the list item bg-color individually using ngFor in Angular 2+ ?
- How to prepend list-item using jQuery with close event ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


