i have any navigation menu !
$("a").click(function()
{
$("a").parent().removeClass("selected");
$(this).parent().addClass("selected");
});
Live Demo
On the assumption that you want to have only one element of class-name selected
I suggest:
$('ul.navigation li a').click(
function(e) {
e.preventDefault(); // prevent the default action
e.stopPropagation(); // stop the click from bubbling
$(this).closest('ul').find('.selected').removeClass('selected');
$(this).parent().addClass('selected');
});
JS Fiddle demo.
you can use toggleClass:
$("#myElement1").click(function(){
$("#myElement2").toggleClass("myClass");
});