search

goog.dom.TagIterator

Provided By
Extends
All Implemented Interfaces
All Known Direct Subclasses

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.

new TagIterator( opt_node, opt_reversed, opt_unconstrained, opt_tagType, opt_depth )

Parameters
opt_node(Node|null)=

The start node. If unspecified or null, defaults to an empty iterator.

opt_reversedboolean=

Whether to traverse the tree in reverse.

opt_unconstrainedboolean=

Whether the iterator is not constrained to the starting node and its children.

opt_tagType(goog.dom.TagWalkType|null)=

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_depthnumber=

The starting tree depth.

Instance Methods

Instance Properties