Reputation: 11
I have this example
$('li').click(function() {
$(this).siblings().removeClass('active');
$(this).addClass('active');
});
All is great but I need another thing. I need that class removes when i click li
with active class again.
Upvotes: 0
Views: 29
Reputation: 79
$('li').click(function() {
$(this).siblings().toggleClass('active');
});
Upvotes: 0
Reputation: 85545
So, replace this line:
$(this).addClass('active');
With this:
$(this).toggleClass('active');
See: toggleClass
Upvotes: 2