Wednesday, July 3, 2024
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!

Nango Kalahttps://www.kala.co.za
Experienced Support Engineer with a demonstrated history of working in the information technology and services industry. Skilled in Microsoft Excel, Customer Service, Microsoft Word, Technical Support, and Microsoft Office. Strong information technology professional with a Microsoft Certificate Solutions Expert (Privet Cloud) focused in Information Technology from Broadband Collage Of Technology.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments