Hi, I''m new to prototype having been introduced because of ruby on rails. Formerly i would be using jquery so i''m a little adept with javascript toolkits. However my problem is that i can''t seem to figure out how to add and remove classes from a list item. for example, my list item is used for navigation, so when a user click on, say, Home Page I want that tab to become ''active.'' What I therefore need to do is remove the class active from any element within my list and add it to the newly clicked item. I hope this makes sence and someone can give me a push in the right direction. Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Element.removeClassName is what you are looking. Probably the most notorious difference with jquery is that arrays don''t get DOM methods, you have to (well, you are advised to) use ''Enumerable.invoke''. anElement.removeClassName("active"); aList.invoke("removeClassName", "active"); If you have at most one active tab (which is usually the case), you can use Element.up and Element.down to move to them, like the following example: $$(".tabs a").invoke("observe", "click", function(event) { event.stop(); // stop the event so it doesn''t actually follow the link this.up(".tabs").down("li.active").removeClassName("active"); // this is the <a> tag clicked // do what you want with the tab, for example: new Ajax.Updater("content", this.readAttribute("href"), { method: "get" }); }); Best, -Nicolas On Jan 3, 2008 4:24 PM, hiddenhippo <redaudi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, I''m new to prototype having been introduced because of ruby on > rails. Formerly i would be using jquery so i''m a little adept with > javascript toolkits. However my problem is that i can''t seem to > figure out how to add and remove classes from a list item. for > example, my list item is used for navigation, so when a user click > on, say, Home Page I want that tab to become ''active.'' What I > therefore need to do is remove the class active from any element > within my list and add it to the newly clicked item. I hope this > makes sence and someone can give me a push in the right direction. > Thanks > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 3, 2008, at 1:24 PM, hiddenhippo wrote:> my list item is used for navigation, so when a user click > on, say, Home Page I want that tab to become ''active.'' What I > therefore need to do is remove the class active from any element > within my list and add it to the newly clicked item. I hope this > makes sence and someone can give me a push in the right direction. > Thanks >Off the top of my head, you could do the following: $$(''li.active'').invoke(''removeClassName'',''active''); $(''id_of_the_new_active'').addClassName(''active''); Walter --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---