onclick change class, remove when next link clicked
I have a side menu that I have added an onclick statement to, which will change the css class for that item to "selected" so that I can apply styles for the selected link. Here is what I have:
How can I modify this so, after one selection is clicked, and you click something else, the class gets removed from the first clicked item, and is now applied to the newly clicked item? I only want the class applied to the currently clicked item, and removed when they click on another item.
After searching I found this nice option. And it works fine if I copy the code and script. But hen I changed the menu link, it doen't work anymore. I hope somebody can tell why. See http://test2.sg-graphics.nl/
I spend a lot of time to find a thing like this. Is there somebody with an other option, maybe with submenu items. But for this site this one is good enough, if it works after changing the link.
Hello vwphillips,
What I'm trying,
I just want a menu with a menu button witch shows an active status. That's where this toppic is about. and the example world with href="#"> But after inserting the right pagelink it doesn't work.
That is because you move to a different page and the class that was loaded onto the nav item is no longer there. My intention when using this script was for ajax pages, which it works nicely, because the nav never changes, only the body content.
Hi Vic,
two part message:
First: is it possible to set the 'selected' as default for the one of the links? (without having it stay selected always)...
Second: I also want to add that your code it is great and really works beautifully!! I just wanted to thank you for posting it to us.
that code is great, but i have a question about it .... i made that onclcick work for <tr> tag but than i have multiple tables on my page and when i click on one <tr> then resets classes in all tables, but i just want to reset classes in table where i am clicking, any idea how to do that ???
thatīs a great code... very usefull, but i have a question. I want to change the class name of a link by clicking another different link, just like changing the menu option by clicking the link of its submenu. But my code is in a way that reloads the page everytime i click the menu option. In other words, how can i change the class name of the menu option when i'm in the page of this menu option? Including setting the 'selected' as default for the home link.
ps: i hope you understand the question... sorry if i wasnt clear.
Bookmarks