EDIT:
After reading the comment on the OP - I believe that this is what he is looking for a way to highlight the โactiveโ link when clicked. And yes, teresko is definitely right that you should switch classes, not identifiers.
This is the essence of the jQuery snippet you might be looking for:
$("li").bind('click', function(){ // remove the active class if it there if($("li.active").length) $("li.active").removeClass('active'); // add teh active class to the clicked element $(this).addClass('active'); });
Demo
Check out jQuery toggle api.
This is a bit confusing because a simple google search in jQuery toggle brings you to the show / hide toggle documentation. But .toggle() can be used to alternate functions - you can even add more than two.
like so...
$("el").toggle( function(){ $(this).css('background-color', 'red'); }, function(){ $(this).css('background-color, ''); // sets the bg-color to nothing });
source share