Delegation sounds like a good model for doing this although if i want
to pass parameters that are custom to each node like which id did it
click on then i assume i have store it as a property on the node and
pass arguments to the delgated function?

In the above example if doIt took a paramter of the id to work on,

doIt(id)  {
// do something to the object with id X
...
}

Then with the delegation model i would have to retreive the node using
findelement and then have an attribute on the node that held the id?
Is that right?

Kiran

On Nov 17, 5:06 am, david <david.brill...@gmail.com> wrote:
> Hi phegaro,
>
> the difference is not about cross browser, because both method is
> cross browser.
> first method come the DOM0 specification and the second one is DOM2.
>
> The big difference is that the DOM0 event could only have ONE
> definition. But for the DOM2 event, you'll have the possibility to
> accept more than one definition.
>
> What I would recommend is to use the DOM2 event and I much more
> recommend  using event delegation:
> instead of observing each element, just observe the parent and get the
> element on the the click is done. So you will have only one event, and
> you could remove or insert element, it will always handle event for
> all elements.
>
> --
> david
>
> On 17 nov, 00:27, phegaro <pheg...@gmail.com> wrote:
>
> > Hi all,
> >   I have an app that is going to put out a list of items onto a page
> > and each one has a number of click targets. Now i could setup the
> > event handler in one of two ways.
>
> > 1. add it into the template that is rendered with the following code
>
> > <div onclick="doIt()" id="item_1" class="item">Item Name 1</div>
>
> > or i could do the following
>
> > 2. Add it using a selector and a script
>
> > $$(".item").each(function(element){element.observe('click', doIt);});
>
> > Are there any issues with option 1 or 2 and which is more performant
> > and cross browser compatible. I think 1 is more performant but not
> > sure it works in all browsers.
>
>

--

You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=.


Reply via email to