Loading ...
Sorry, an error occurred while loading the content.

DOM versus Element

Expand Messages
  • Larry
    What s the deal with the new Element utility? I see that it has some of the same methods as the older DOM utility. Is Element going to replace DOM or what?
    Message 1 of 2 , Nov 28, 2007
    View Source
    • 0 Attachment
      What's the deal with the new Element utility? I see that it has some of
      the same methods as the older DOM utility. Is Element going to replace
      DOM or what? Which am I supposed to use?

      I apologize if this has been covered, but I couldn't find anything. It
      sure would be nice if this was explained in the online documentation.

      Confused.
    • Matt Sweeney
      Hi Larry, Dom is a standalone utility that provides static methods for common Dom tasks. Same goes for Event. for example:
      Message 2 of 2 , Nov 29, 2007
      View Source
      • 0 Attachment
        Hi Larry,

        Dom is a standalone utility that provides static methods for common Dom
        tasks. Same goes for Event.

        for example:
        YAHOO.util.Dom.addClass(someElement, 'foo');
        YAHOO.util.Event.on(someElement, 'click', handleClick);

        Element is a wrapper for an HTMLElement that brings Event, Attributes,
        and Dom together under a common API.

        for example:
        var myEl = new YAHOO.util.Element(someElement);
        myEl.addClass('foo');
        myEl.on('click', handleClick);

        The utilities are great for when you just want to handle an event, set a
        style, or add a class to an element and be done.

        Element is useful when you have more tasks to perform as it allows you
        to directly address the utility methods on the element itself. Creating
        an Element simply to addClass, addListener, or some other basic task is
        probably overkill.

        Sorry about the confusion. Hope this helps.

        Matt

        Larry wrote:
        > What's the deal with the new Element utility? I see that it has some of
        > the same methods as the older DOM utility. Is Element going to replace
        > DOM or what? Which am I supposed to use?
        >
        > I apologize if this has been covered, but I couldn't find anything. It
        > sure would be nice if this was explained in the online documentation.
        >
        > Confused.
        >
        >
        >
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.