what is dom helper?

325 views
Skip to first unread message

Evgeny

unread,
Feb 18, 2010, 5:38:25 PM2/18/10
to Closure Library Discuss
might someone explain what the concept of DOM Helper means?

When does it come in useful/necessary?

Erik Arvidsson

unread,
Feb 18, 2010, 5:48:30 PM2/18/10
to closure-lib...@googlegroups.com
The DomHelper is useful when working with the DOM in different frames
and windows.

erik

M. David Westbrook

unread,
Feb 18, 2010, 8:52:15 PM2/18/10
to closure-lib...@googlegroups.com
Some more info:

Many DOM manipulation operations require a reference to the Document
object that contains the manipulated nodes. Any such operations
defined in goog.dom are defined as methods of the DomHelper class,
which keeps a reference to a Document.

If you only want to work with a single frameless window, you don't
ever actually need to construct a DomHelper object. The goog.dom
package automatically creates a DomHelper for the document in which
the package is included.

The package also creates aliases for this DomHelper's methods at the
goog.dom level. If, for example, you want to use goog.dom.DomHelper's
getElement() method to retrieve an element and all of your html and
JavaScript (including the goog.dom code) is included in a single
document, you just need to call goog.dom.getElement().

You may, however, need to work with the DOM of a document other than
goog.dom's home document, in which case you must construct your own
DomHelper and use its instance methods directly rather than calling
the goog.dom versions of those methods. If, for example, you need to
work with the contents of multiple frames, create a separate DomHelper
for each frame's document, like so:

var frameHelper = new goog.dom.DomHelper(frameDocument);

Then you can call frameHelper.getElement() to get elements within that frame.

David

Reply all
Reply to author
Forward
0 new messages