July 13, 2012

Active menu background color

Question by user1522624

I have a vertical menu. It is .glossymenu . The menu item is accessed using css as .glossymenu a.menuitem . I want to change the background color when the menu item is selected or when the menu item is active. I am trying to use the following JQuery:

$(".glossymenu a.menuitem").click(function(){
  $(this).siblings(".active").removeClass("active");
  $(this).addClass("active");
});

But, I am unable to resolve my issue using this. Any ideas, how to change the background color of the menu item, when it is selected. It should not change when we click outside the menu item in blank area, when the menu is active.
Thanks,
Prasad

Answer by Starx

Active state is available in CSS and it much better to use that one instead.

a.menuitem:active { background-color: #c00; }

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!