HTML DOM item() Method

Last Updated : 4 Aug, 2026

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

html
<!--Driver Code Starts-->

<!DOCTYPE html>
<html>

<head>
    <title>
        HTML DOM item() Method
    </title>
    <!-- script to change node value -->
<!--Driver Code Ends-->

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

<!--Driver Code Starts-->
    </center>
</body>

</html>  

<!--Driver Code Ends-->
Comment