Just trying to figure out how you can test multiple selectors within an existing piece of code i.e. like this
if (!(jQuery('#selector1 || #selector2').hasClass('some-class'))) {
//code here
}
This doesn't work but wondering if there is anything I can do to make it work ?
Just select them both, if either of them has the class some-class
, the condition is true:
if (!jQuery('#selector1, #selector2').hasClass('some-class')) {
//code here
}
Or, if I misinterpreted your logic, you can (and should, for sake of speed and simplicity) break those into two:
if (!(jQuery('#selector1').hasClass('some-class') || jQuery('#selector2').hasClass('some-class'))) {
//code here
}
Quite simple, it's a comma ;)
if (!(jQuery('#selector1 .some-class, #selector2 .some-class'))) {
//code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With