Reputation: 10246
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
}
Upvotes: 2
Views: 13375
Reputation: 707248
There is also the non jQuery way using a regex on the class name directly:
if (!this.className.match(/\bagallery\b|\baslide\b/)) {
// do certain things
}
Upvotes: 2
Reputation: 284786
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.
Upvotes: 6
Reputation: 36957
Try using &&
instead:
if(!$(this).hasClass('agallery') && !$(this).hasClass('aslide')){
//do certain things
}
Upvotes: 2