Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery selecting all classes except one

Tags:

jquery

I want to do something like so:

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

In this line i want to add an exception, so that i wouldnt include $(this):

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

Can this be done?

like image 843
Edgar Avatar asked Jan 13 '23 11:01

Edgar


1 Answers

not() will do it.

$('.anwer_labels').not(this).removeClass('active');
like image 67
alex Avatar answered Jan 23 '23 00:01

alex