user3241193
user3241193

Reputation: 11

Jquery active class trouble

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

Answers (2)

Adrian Brown
Adrian Brown

Reputation: 79

 $('li').click(function() {
    $(this).siblings().toggleClass('active');
 });

Upvotes: 0

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

So, replace this line:

$(this).addClass('active');

With this:

$(this).toggleClass('active');

See: toggleClass

Upvotes: 2

Related Questions