Packagedom.tr.traversal
Interfacepublic interface NodeIterator

Introduced in: DOM 2 Core 

Allows you to iterate over the members of a list of the nodes in a subtree of the DOM, in document order. A NodeIterator can be created using the createNodeIterator() method of the Document object, as follows:
var nodeIterator = document.createNodeIterator();

See also

MDC - NodeIterator
W3C - DOM Level 2 Traversal: NodeIterator


Public Properties
 PropertyDefined By
  DOM 2 TR expandEntityReferences : Boolean
[read-only] Returns a flag indicating whether or not the children of entity reference nodes are visible to the NodeIterator.
NodeIterator
  DOM 2 TR filter : NodeFilter
[read-only] Returns an object with a method acceptNode(node).
NodeIterator
  Non-Standard pointerBeforeReferenceNode : Boolean
[read-only] A Boolean value that indicates whether the NodeIterator is anchored before (if this value is true) or after (if this value is false) the anchor node indicated by the referenceNode property.
NodeIterator
  Non-Standard referenceNode : Node
[read-only] Returns the node to which the iterator is anchored; as new nodes are inserted, the iterator remains anchored to the reference node as specified by this property.
NodeIterator
  DOM 2 TR root : Node
[read-only] Returns the node that is the root of what the NodeIterator traverses.
NodeIterator
  DOM 2 TR whatToShow : Number
[read-only] Returns a number signifying what types of nodes should be returned by the NodeIterator.
NodeIterator
Public Methods
 MethodDefined By
  
DOM 2 TR detach():void
Detaches the NodeIterator from the set over which it iterates, releasing any resources used by the set and setting the iterator's state to INVALID.
NodeIterator
  
DOM 2 TR nextNode():Node
Returns the next node in the set represented by the NodeIterator and advances the position of the iterator within the set.
NodeIterator
  
DOM 2 TR previousNode():Node
Returns the previous node in the set and moves the position of the NodeIterator backwards in the set.
NodeIterator
Property Detail
DOM 2 TR expandEntityReferencesproperty
expandEntityReferences:Boolean  [read-only]

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5 Safari 3.0 Safari 3.1 Safari 4.0b Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0a
Introduced in: DOM 2 Core 

Returns a flag indicating whether or not the children of entity reference nodes are visible to the NodeIterator.

If this value is false, the children of entity reference nodes (as well as all of their descendants) are rejected. This takes precedence over the whatToShow value and the filter.


Implementation
    public function get expandEntityReferences():Boolean

See also


Example
         var nodeIterator = document.createNodeIterator(
             document.body,
             NodeFilter.SHOW_ELEMENT,
             { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
             false
             );
         expand = nodeIterator.expandEntityReferences;
DOM 2 TR filterproperty 
filter:NodeFilter  [read-only]

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5 Safari 3.0 Safari 3.1 Safari 4.0b Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0a
Introduced in: DOM 2 Core 

Returns an object with a method acceptNode(node). This is the NodeFilter used to screen nodes.

Note: When creating the NodeIterator, the filter object is passed in as the third parameter, and the object method acceptNode(node) is called on every single node to determine whether or not to accept it. This function should return the constant NodeFilter.FILTER_ACCEPT for cases when the node should be accepted and NodeFilter.FILTER_REJECT for cases when the node should be rejected.


Implementation
    public function get filter():NodeFilter

See also


Example
         var nodeIterator = document.createNodeIterator(
             document.body,
             NodeFilter.SHOW_ELEMENT,
             { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
             false
             );
         nodeFilter = nodeIterator.filter
pointerBeforeReferenceNodeproperty 
pointerBeforeReferenceNode:Boolean  [read-only]

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5 Safari 3.0 Safari 3.1 Safari 4.0b Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0a

Non-standard (Mozilla)

A Boolean value that indicates whether the NodeIterator is anchored before (if this value is true) or after (if this value is false) the anchor node indicated by the referenceNode property.

Note: This property was introduced by WebKit and is used for testing; it can also be used by debuggers. It is not part of the DOM specification.


Implementation
    public function get pointerBeforeReferenceNode():Boolean

See also


Example
         var nodeIterator = document.createNodeIterator(
             document.body,
             NodeFilter.SHOW_ELEMENT,
             { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
             false
             );
         flag = nodeIterator.pointerBeforeReferenceNode;
referenceNodeproperty 
referenceNode:Node  [read-only]

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5 Safari 3.0 Safari 3.1 Safari 4.0b Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0a

Non-standard (Mozilla)

Returns the node to which the iterator is anchored; as new nodes are inserted, the iterator remains anchored to the reference node as specified by this property.

Note: This property was introduced by WebKit and is used for testing; it can also be used by debuggers. It is not part of the DOM specification.


Implementation
    public function get referenceNode():Node

See also


Example
         var nodeIterator = document.createNodeIterator(
             document.body,
             NodeFilter.SHOW_ELEMENT,
             { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
             false
             );
         node = nodeIterator.referenceNode;
DOM 2 TR rootproperty 
root:Node  [read-only]

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5 Safari 3.0 Safari 3.1 Safari 4.0b Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0a
Introduced in: DOM 2 Core 

Returns the node that is the root of what the NodeIterator traverses.


Implementation
    public function get root():Node

See also


Example
         var nodeIterator = document.createNodeIterator(
             document.body,
             NodeFilter.SHOW_ELEMENT,
             { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
             false
             );
         root = nodeIterator.root; // document.body in this case
DOM 2 TR whatToShowproperty 
whatToShow:Number  [read-only]

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5 Safari 3.0 Safari 3.1 Safari 4.0b Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0a
Introduced in: DOM 2 Core 

Returns a number signifying what types of nodes should be returned by the NodeIterator.

The available set of constants is defined in the NodeFilter interface. Nodes not accepted by whatToShow will be skipped, but their children may still be considered. Note that this skip takes precedence over the filter, if any.


Implementation
    public function get whatToShow():Number

See also


Example
         var nodeIterator = document.createNodeIterator(
             document.body,
             NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_COMMENT + NodeFilter.SHOW_TEXT,
             { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
             false
             );
         if((nodeIterator.whatToShow == NodeFilter.SHOW_ALL) || 
             (nodeIterator.whatToShow % (NodeFilter.SHOW_COMMENT)) >= NodeFilter.SHOW_COMMENT) {
             // nodeIterator will show comments
         }
Method Detail
DOM 2 TR detach()method
public function detach():void

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5 Safari 3.0 Safari 3.1 Safari 4.0b Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0a
Introduced in: DOM 2 Core 

Detaches the NodeIterator from the set over which it iterates, releasing any resources used by the set and setting the iterator's state to INVALID.

Once this method has been called, calls to other methods on NodeIterator will raise the INVALID_STATE_ERR exception.

See also


Example
         var nodeIterator = document.createNodeIterator(
             document.body,
             NodeFilter.SHOW_ELEMENT,
             { acceptNode: function(node) { return NodeFilter.FILTER_ACCEPT; } },
             false
             );
         nodeIterator.detach(); // detaches the iterator
         
         nodeIterator.nextNode(); // throws an INVALID_STATE_ERR exception
DOM 2 TR nextNode()method 
public function nextNode():Node

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5 Safari 3.0 Safari 3.1 Safari 4.0b Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0a
Introduced in: DOM 2 Core 

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.

Returns
Node — The next Node in the set being iterated over, or null if there are no more members in that set.

Throws
DOMException — INVALID_STATE_ERR: Raised if this method is called after the detach method was invoked.

See also


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
DOM 2 TR previousNode()method 
public function previousNode():Node

Product Versions : Internet Explorer 5.5 Internet Explorer 6.0 Internet Explorer 7.0 Internet Explorer 8.0 as IE7 Internet Explorer 8.0 as IE8 Firefox 2.0 Firefox 3.0 Firefox 3.5 Safari 3.0 Safari 3.1 Safari 4.0b Chrome 1.0 Chrome 2.0 Opera 9.62 Opera 10.0a
Introduced in: DOM 2 Core 

Returns the previous node in the set and moves the position of the NodeIterator backwards in the set.

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

Returns
Node — The previous Node in the set being iterated over, or null if there are no more members in that set.

Throws
DOMException — INVALID_STATE_ERR: Raised if this method is called after the detach method was invoked.

See also


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