dom.TagIterator Extends goog.iter.Iterator
A DOM tree traversal iterator. Starting with the given node, the iterator walks the DOM in order, reporting events for the start and end of Elements, and the presence of text nodes. For example:
<div>1<span>2</span>3</div>
Will return the following nodes: [div, 1, span, 2, span, 3, div] With the following states: [START, OTHER, START, OTHER, END, OTHER, END] And the following depths [1, 1, 2, 2, 1, 1, 0] Imagining | represents iterator position, the traversal stops at each of the following locations:
<div>|1|<span>|2|</span>|3|</div>|
The iterator can also be used in reverse mode, which will return the nodes and states in the opposite order. The depths will be slightly different since, like in normal mode, the depth is computed *after* the given node. Lastly, it is possible to create an iterator that is unconstrained, meaning that it will continue iterating until the end of the document instead of until exiting the start node.

Inheritance

Constructor

goog.dom.TagIterator(opt_nodeopt_reversedopt_unconstrainedopt_tagTypeopt_depth)

Parameters

opt_node : Node=
The start node. If unspecified or null, defaults to an empty iterator.
opt_reversed : boolean=
Whether to traverse the tree in reverse.
opt_unconstrained : boolean=
Whether the iterator is not constrained to the starting node and its children.
opt_tagType : goog.dom.TagWalkType?=
The type of the position. Defaults to the start of the given node for forward iterators, and the end of the node for reverse iterators.
opt_depth : number=
The starting tree depth.

Instance Methods

Public Protected Private
clone() !goog.dom.TagIterator
No description.
Returns: !goog.dom.TagIterator  A copy of this iterator.
code »
copyFrom(other)
Replace this iterator's values with values from another. The two iterators must be of the same type.
Arguments:
other : goog.dom.TagIterator
The iterator to copy.
code »
equals(other) boolean
Test if two iterators are at the same position - i.e. if the node and tagType is the same. This will still return true if the two iterators are moving in opposite directions or have different constraints.
Arguments:
other : goog.dom.TagIterator
The iterator to compare to.
Returns: boolean  Whether the two iterators are at the same position.
code »
isEndTag() boolean
No description.
Returns: boolean  Whether this iterator's position is an end tag position.
code »
isNonElement() boolean
No description.
Returns: boolean  Whether this iterator's position is not at an element node.
code »
isStartTag() boolean
No description.
Returns: boolean  Whether this iterator's position is a start tag position.
code »
isStarted() boolean
No description.
Returns: boolean  Whether next has ever been called on this iterator.
code »
next() Node
Move to the next position in the DOM tree.
Returns: Node  Returns the next node, or throws a goog.iter.StopIteration exception if the end of the iterator's range has been reached.
code »
restartTag()
Restart the current tag.
code »
setPosition(nodeopt_tagTypeopt_depth)
Set the position of the iterator. Overwrite the tree node and the position type which can be one of the goog.dom.TagWalkType token types. Only overwrites the tree depth when the parameter is specified.
Arguments:
node : Node
The node to set the position to.
opt_tagType : goog.dom.TagWalkType?=
The type of the position Defaults to the start of the given node.
opt_depth : number=
The tree depth.
code »
skipTag()
Skip the current tag.
code »
splice(var_args)
Replace the current node with the list of nodes. Reset the iterator so that it visits the first of the nodes next.
Arguments:
var_args : ...Object
A list of nodes to replace the current node with. If the first argument is array-like, it will be used, otherwise all the arguments are assumed to be nodes.
code »
__iterator__(opt_keys) !goog.iter.Iterator.<VALUE>
Returns the Iterator object itself. This is used to implement the iterator protocol in JavaScript 1.7
Arguments:
opt_keys : boolean=
Whether to return the keys or values. Default is to only return the values. This is being used by the for-in loop (true) and the for-each-in loop (false). Even though the param gives a hint about what the iterator will return there is no guarantee that it will return the keys when true is passed.
Returns: !goog.iter.Iterator.<VALUE>  The object itself.
code »
next() VALUE
Returns the next value of the iteration. This will throw the object when the iteration passes the end.
Returns: VALUE  Any object or value.
code »

Instance Properties

constrained :
Whether the iterator is constrained to the starting node and its children.
Code »
constructor :
No description.
Code »
depth :
The tree depth of this position relative to where the iterator started. The depth is considered to be the tree depth just past the current node, so if an iterator is at position
|
(i.e. the node is the div and the type is START_TAG) its depth will be 1.
Code »
node :
The node this position is located on.
Code »
reversed :
Whether the node iterator is moving in reverse.
Code »
started_ :
Whether iteration has started.
Code »
tagType :
The type of this position.
Code »

Static Properties

goog.dom.TagIterator.superClass_ :
No description.
Code »

Package dom

Package Reference