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 <[email protected]> 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
