I would like to test an element object to see if it has either “classA” or “classB”. For example, a click() event has returned an element in the event’s target property. I want to test this element to see if has either of those two classes.
$("#mybutton").click(function($event) {
var $el = $($event.target);
if($el.is(".classA") || $el.is(".classB")) {
// Can I do the above with 1 selector instead of two separate ones?
}
});
As above, using the is() function, I can check for each class individually, but I’m curious if I can do it with one function call instead of two?
Yes, you can separate the selectors with a comma:
See it in action.