I''m trying to apply a css class to all LI elements that are children of an element with the ID "idSelector". This is what I did and it works. But I was wondering if there was an easier way without having to use an anonymous function? $$("#idSelector li").each(function() { arguments[0].addClassName("myClass") }); Thanks in advance. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
the group might correct me if im wrong but i think you might be able to use invoke [''hello'', ''world'', ''cool!''].invoke(''substring'', 0, 3) // [''hel'', ''wor'', ''coo''] soo $$("#idSelector li").invoke(''addClassName'',''myClass''); Gareth On 6/9/07, Camsoft <camcooke-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I''m trying to apply a css class to all LI elements that are children > of an element with the ID "idSelector". > This is what I did and it works. But I was wondering if there was an > easier way without having to use an anonymous function? > > $$("#idSelector li").each(function() > { arguments[0].addClassName("myClass") }); > > Thanks in advance. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey, Camsoft a écrit :> This is what I did and it works. But I was wondering if there was an > easier way without having to use an anonymous function?Certainly. As emphasized on the pages for each and map/collect, calling the same function with identical arguments throughout an enum is an optimized use-case: use invoke, as in the rewrite below. $$(''#idSelector > li'').invoke(''addClassName'', ''myClass''); (btw, I used ''>'' instead of a simple space because you said you wanted only "children" <li>''s to be affected. If you''re going for descendants, do use a simple space instead of the closing angular bracket. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Beat you by 2 mins Christophe... but yours was quicker with the > instead of space :) On 6/9/07, Christophe Porteneuve <tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> > > Hey, > > Camsoft a écrit : > > This is what I did and it works. But I was wondering if there was an > > easier way without having to use an anonymous function? > > Certainly. As emphasized on the pages for each and map/collect, calling > the same function with identical arguments throughout an enum is an > optimized use-case: use invoke, as in the rewrite below. > > $$(''#idSelector > li'').invoke(''addClassName'', ''myClass''); > > (btw, I used ''>'' instead of a simple space because you said you wanted > only "children" <li>''s to be affected. If you''re going for descendants, > do use a simple space instead of the closing angular bracket. > > -- > Christophe Porteneuve aka TDD > tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thats great, thanks all for your help, that worked well. On 9 Jun, 10:43, "Gareth Evans" <agr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Beat you by 2 mins Christophe... but yours was quicker with the > instead of > space :) > > On 6/9/07, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote: > > > > > > > Hey, > > > Camsoft a écrit : > > > This is what I did and it works. But I was wondering if there was an > > > easier way without having to use an anonymous function? > > > Certainly. As emphasized on the pages for each and map/collect, calling > > the same function with identical arguments throughout an enum is an > > optimized use-case: use invoke, as in the rewrite below. > > > $$(''#idSelector > li'').invoke(''addClassName'', ''myClass''); > > > (btw, I used ''>'' instead of a simple space because you said you wanted > > only "children" <li>''s to be affected. If you''re going for descendants, > > do use a simple space instead of the closing angular bracket. > > > -- > > Christophe Porteneuve aka TDD > > t...-x+CfDp/qHesRuZII/U6RgQ@public.gmane.org Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---