NodeIterator.previousNode

  • Revision slug: DOM/NodeIterator.previousNode
  • Revision title: NodeIterator.previousNode
  • Revision id: 136553
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment page created, 94 words added

Revision Content

{{ DomRef() }}

{{ fx_minversion_header("3") }}

Summary

Returns the previous node in the set represented by the NodeIterator and advances the position of the iterator within the set.

This method returns null when the current node is the first node in the set.

Throws the INVALID_STATE_ERR DOMException if this method is called after the detach() method.

Syntax

node = nodeIterator.previousNode();

Example

var nodeIterator = document.createNodeIterator(
    document.body,
    NodeFilter.SHOW_ELEMENT,
    { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
    false
);
currentNode = nodeIterator.nextNode(); // returns the next node
previousNode = nodeIterator.previousNode(); // same result, since we backtracked to the previous node

Revision Source

<p>{{ DomRef() }}</p>
<p>{{ fx_minversion_header("3") }}</p>
<h3 name="Summary">Summary</h3>
<p>Returns the previous node in the set represented by the <a class="internal" href="/En/DOM/NodeIterator" title="En/DOM/NodeIterator"><code>NodeIterator</code></a> and advances the position of the iterator within the set.</p>
<p>This method returns <code>null</code> when the current node is the first node in the set.</p>
<p>Throws the <code>INVALID_STATE_ERR</code> <code>DOMException</code> if this method is called after the <a class="internal" href="/En/DOM/NodeIterator.detach" title="En/DOM/NodeIterator.detach"><code>detach()</code></a> method.</p>
<h3 name="Syntax">Syntax</h3>
<pre class="eval">node = nodeIterator.previousNode();
</pre>
<h3 name="Example">Example</h3>
<pre class="eval">var nodeIterator = document.createNodeIterator(
    document.body,
    NodeFilter.SHOW_ELEMENT,
    { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
    false
);
currentNode = nodeIterator.nextNode(); // returns the next node
previousNode = nodeIterator.previousNode(); // same result, since we backtracked to the previous node
</pre>
Revert to this revision