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?


On Nov 17, 5:06 am, david <> 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 <> 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 &" group.
To post to this group, send email to
For more options, visit this group at

Reply via email to