> some form controls (radio, checkbox, maybe others...) have a native > click() method that toggles them, so that would be in conflict...
Nice one, *exactly* why this sort of thing is not generally a good idea. Create a utility class to do it, etc., but putting them on the actual elements is asking for trouble. Re the `click` event on form controls (which are Elements, of course): http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html#ID-2651361 -- T.J. :-) On Dec 3, 6:16 am, Gappa <[email protected]> wrote: > Hi, > > some form controls (radio, checkbox, maybe others...) have a native > click() method that toggles them, so that would be in conflict I > suppose. > > Pavel > > On 2 pro, 10:36, Luke <[email protected]> wrote: > > > > > > > > > Hi, > > > I think it's pretty annoying to write > > > myelement.observe('click', function(event){ > > // do stuff > > event.stop() > > > }); > > > for every link etc for which you want to replace the click- > > functionality. So I added a Method to Element that does the observer- > > invoking and event-stopping for me and simply named it click. Like > > with jQuery, the event only keeps bubbling if the given eventHandler > > returns true. > > > Element.addMethods({ > > click: function(element, eventHandler) { > > if (!(element = $(element))) return; > > element.observe('click', function(event){ > > if(!eventHandler(event)) > > event.stop() > > }); > > return element; > > } > > > }); > > > But I'm wondering. 'click' sounds like a name to me that could easily > > cause conflicts. It works in Safari and FF though. Does anyone know if > > there could be sideeffects or nameconflicts? > > > Thanks > > Lukas -- 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.
