Jquery selecting all classes except one

I want to do something like this:

$('.anwer_labels').click(function() { $(this).toggleClass('active'); $('.anwer_labels').removeClass('active'); // $(this).addClass('active').siblings().removeClass('active');; // $(this).removeClass('active'); }) 

On this line, I want to add an exception, so I would not include $(this) :

 $('.anwer_labels').removeClass('active'); //some code here to not add $(this) 

Can this be done?

+4
source share
2 answers

not() will do this.

 $('.anwer_labels').not(this).removeClass('active'); 
+9
source

You can use not ()

Description: selects all elements that do not match the specified selector.

code:

 $('.anwer_labels').not(this).removeClass('active'); 
0
source

All Articles