$(document).on('click', '.SELECTOR1 OR #SELECTOR2', function(){
// some code
});
What I want to achieve is to run some code if either one of the elements is clicked.
The Sizzle selector engine that jQuery uses follows the same rules as CSS. With that in mind you can separate selectors using ,
:
$(document).on('click', '.SELECTOR1, #SELECTOR2', function(){
// some code
});
Simply use a comma to do that:
$(document).on('click', '.SELECTOR1, #SELECTOR2', function(){
// some code
});
JSFIDDLE.
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