Sunday, December 14, 2025
HomeLanguagesJavascriptHTML DOM NodeIterator nextNode() Method

HTML DOM NodeIterator nextNode() Method

The NodeIterator.nextNode() method sets the NodeIterator to next node in the document and returns the nextNode. The first call of the nextNode() returns the first node in the set.

This method returns null when there are no nodes left in the set.

Syntax:

node = nodeIterator.nextNode();

Parameters: This method takes no parameter.

Return Value: This method returns the next node in the set.

Example: In this example, we will create a node iterator and hence will iterate using the nextNode() method.




<!DOCTYPE HTML> 
<html>  
<head>
    <meta charset="UTF-8">
    <title>HTML | DOM nextNode() Method</title>
</head>   
  
<body style="text-align:center;">
    <h1 style="color:green;">  
     neveropen
    </h1> 
    <p> 
HTML | DOM nextNode() Method
    </p>
  
    <button onclick = "Geeks()">
    Click Here
    </button>
    <p id="a"></p>
    <script> 
        var a = document.getElementById("a");
        function Geeks(){
           const nodeIterator = document.createNodeIterator(
                document.body,
                NodeFilter.SHOW_ELEMENT
                )
             
            let nextNode=nodeIterator.nextNode();
            nextNode=nodeIterator.nextNode();
            nextNode=nodeIterator.nextNode();
            a.innerHTML =
'Next Node content is : '+nextNode.textContent;
            console.log(nextNode);
}
</script>
</body>
</html>


Output:

Before Clicking Button:

After Clicking Button:

In the console: in Console, the next node can be seen.

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Safari
  • Opera
  • Internet Explorer
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32448 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6817 POSTS0 COMMENTS
Nicole Veronica
11954 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12031 POSTS0 COMMENTS
Shaida Kate Naidoo
6954 POSTS0 COMMENTS
Ted Musemwa
7202 POSTS0 COMMENTS
Thapelo Manthata
6899 POSTS0 COMMENTS
Umr Jansen
6883 POSTS0 COMMENTS