Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery hasClass without breaking chain

Tags:

jquery

I am trying to add a jquery selector which finds: all data-toggle=collapse which dont have a class of no-hide

I try which doesn't select anything.

$('[data-toggle=collapse]:has(.no-hide)').click(function(){ 

Error: $(...).hasClass(...).click is not a function

$('[data-toggle=collapse]').hasClass("no-hide").click(function(){ 

Only works if there is 1 class name.

$('[data-toggle=collapse][class=no-hide]').click(function(){
like image 917
John Magnolia Avatar asked Jun 04 '26 11:06

John Magnolia


2 Answers

You can use not method:

$('[data-toggle=collapse]').not(".no-hide").click(function(){ 

Update: If you want to select the elements that have no-hide class, you can use filter method:

$('[data-toggle=collapse]').filter(".no-hide").click(function(){ 
like image 101
undefined Avatar answered Jun 07 '26 21:06

undefined


try not

$('[data-toggle=collapse]').not(".no-hide").click(function(){ 
   //your stuff
});
like image 40
bipen Avatar answered Jun 07 '26 19:06

bipen