ben.keen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-05 02:01 UTC
Assigning event handler to multiple elements
Simple question: I need to add an onchange handler to multiple elements (say, 50 of them). Any suggestions on the most elegant solution to this using Prototype? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
$$(''css selector for
elements'').invoke(''observe'',
''click'', function(e) { for
click });
or if you need to assign different handlers you have a few options such as
each with type checks followed by an observe call..
http://www.prototypejs.org/api/utility#method-$$
http://www.prototypejs.org/api/enumerable/invoke
If your clickable elements have a common parent, it is more efficent to
observe the click event on the parent and allow bubbling to keep your
resources down.
Gareth Evans
On Dec 5, 2007 3:01 PM, ben.keen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
<ben.keen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> Simple question: I need to add an onchange handler to multiple
> elements (say, 50 of them). Any suggestions on the most elegant
> solution to this using Prototype?
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
ben.keen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-05 02:14 UTC
Re: Assigning event handler to multiple elements
Marvellous! Very clear - thanks for the help. - Ben On Dec 4, 8:07 pm, "Gareth Evans" <agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> $$(''css selector for elements'').invoke(''observe'', ''click'', function(e) { for > click }); > or if you need to assign different handlers you have a few options such as > each with type checks followed by an observe call.. > > http://www.prototypejs.org/api/utility#method-$$http://www.prototypejs.org/api/enumerable/invoke > > If your clickable elements have a common parent, it is more efficent to > observe the click event on the parent and allow bubbling to keep your > resources down. > > Gareth Evans > > On Dec 5, 2007 3:01 PM, ben.k...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <ben.k...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Simple question: I need to add an onchange handler to multiple > > elements (say, 50 of them). Any suggestions on the most elegant > > solution to this using Prototype?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---