HTML | DOM item() Method

The item() method is used to return the node at specified index. The node are sorted as they appear in the source code. The index of 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>
        <div id = "geeks">
            <p>GeeksforGeeks</p>
            <p>A computer science portal</p>
            <p>DOM item() Method</p>
        </div>
          
        <button onclick = "changeElement()">
            Click Here!
        </button>
    </body>
</html>                    

chevron_right


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
  • Apple Safari
  • Firefox
  • Opera
  • Internet Explorer


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.




Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.