Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery hasClass conditional

The conditional should be met only if the clicked element has no class agallery or aslide. This is not working for me.

if(!$(this).hasClass('agallery') || !$(this).hasClass('aslide')){
  //do certain things
}
like image 386
Pinkie Avatar asked Dec 06 '25 08:12

Pinkie


1 Answers

if(!($(this).hasClass('agallery') || $(this).hasClass('aslide'))){

Basically, you should read this as "not (either A or B)", while Clive's equivalent is "(not A) and (not B)".

Your condition "(not A) or (not B)" is true if it doesn't have one. So it will only be false if it has both classes.

like image 198
Matthew Flaschen Avatar answered Dec 08 '25 22:12

Matthew Flaschen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!