This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

nextNode

Summary

The NodeIterator.nextNode() method returns the next node in the set represented by the NodeIterator and advances the position of the iterator within the set. The first call to nextNode() returns the first node in the set.

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

Method of dom/NodeIteratordom/NodeIterator

Syntax

var object = object.nextNode(/* see parameter list */);

Parameters

oNode

Data-type
any


Object containing the next node in the list.

Return Value

Returns an object of type DOM NodeDOM Node

Type: HRESULT

This method can return one of these values.

Return code Description
S_OK The operation completed successfully.
InvalidStateError _ERR NodeIterator raises this exception if detach has been invoked on the object.

Node

Object containing the next node in the list.

Examples

<!DOCTYPE html>
<html>
<head>
<title>NextNode example</title>
  <script type="text/javascript">
    function LoseMondays(){
      var ni = document.createNodeIterator(document.body, NodeFilter.SHOW_TEXT, null, false);
      var txt = ni.nextNode();      //go to first node of our NodeIterator
      while (txt)                   //while text
        {
          if (txt.wholeText.match('Monday') || txt.parentNode.getAttribute('id') == 'Monday')
            {
            txt.parentNode.removeChild(txt);        //remove monday's activity
            }
          txt=ni.nextNode();                        //go to next node
        }
    }
    function refresh()                 
      {
        window.location.reload( false );           //reload our page
      }
  </script>
</head>
<body>
    <p><strong>Harry's weekly diary</strong></p>
    <p>Monday Joe bought a turkey.</p>
    <p>Tuesday Bill bought a pound of ham.</p>
    <div>Chuck called in sick Monday.</div>
    <p id="Monday">CALL supplier today</p>
    <p>Wednesday's delivery was delayed.</p>
    <input type="button" name="reset" value="refresh" onclick="refresh()"/>
    <input type="button" name="cutmonday" value="Lose Mondays" onclick="LoseMondays()"/>
</body>
</html>


Notes

Remarks

This example shows how to create a NodeIterator and move forward through the list of nodes.

Syntax

node = nodeIterator.nextNode();

Standards information

Related specifications

DOM
Living Standard

Attributions