Reputation: 46479
Basically I am trying to figure out the following I have several elements like
<a href="#" clas="v-bar"></a>
<a href="#" clas="v-bar"></a>
<a href="#" clas="v-bar"></a>
<a href="#" clas="v-bar"></a>
<a href="#" clas="v-bar"></a>
I need to figure out how to add class to an element when it is clicked, so for example add .v-current
, but at the same time remove it from all other elements with a class of .v-bar
? All with jQuery.
Upvotes: 1
Views: 1258
Reputation: 803
$('.v-bar').click(function(){
$('.v-current').removeClass('v-current');
$(this).addClass('v-current');
});
Upvotes: 1
Reputation: 56688
$('.v-bar').click(function(e){
$('.v-bar').removeClass('v-current');
$(this).addClass('v-current');
e.preventDefault();
});
Upvotes: 3