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

Re: [ydn-javascript] Dom and Element: When to use which?

Expand Messages
  • Eric Miraglia
    Shiu, The Dom Collection is a utility that has many convenience methods for manipulating an element s properties, but think of it more as a general DOM API
    Message 1 of 2 , May 2, 2007
    • 0 Attachment
      Shiu,

      The Dom Collection is a utility that has many convenience methods for manipulating an element's properties, but think of it more as a general DOM API helper collection.  Use Dom when you want to interact with elements on the page, setting their style or changing their CSS class or doing other common manipulations.  The Dom Collection also provides powerful methods for getting element collections (by CSS class, by custom tests, etc.), for positioning elements, etc.

      The Element Utility is a more complete wrapper for a single element.  You would use the Element Utility where you were going to perform many operations (including multiple event attachment, attribute manipulation, etc.) to a single element over the course of its life. Reserve the Element Utility to wrap elements that you're doing a lot of stuff to and where you need its advanced features.  For example, Element can notify you when a specific attribute is changed on an element, and it allows you to subscribe multiple methods to, say, an element's click event while only creating a single DOM event handler.

      A good rule of thumb is that where your needs are met by using the Dom Collection and the Event Utility to manage your interaction with an element, you should use them directly.  When you are doing intensive and more far-reaching interaction with an element over time (as you frequently do in developing UI widgets, for example), Element provides a good architecture for that.

      Regards,
      Eric


      ______________________________________________
      Eric Miraglia
      Yahoo! User Interface Library



      On May 1, 2007, at 10:21 AM, ahbeng36 wrote:

      Hi,

      Dom and Element are doing similar things. I am wondering when to use
      which. Can anyone give me some advice?

      Thank you

      Shiu


    Your message has been successfully submitted and would be delivered to recipients shortly.