Reputation: 1152
$(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.
Upvotes: 5
Views: 677
Reputation: 337713
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
});
Upvotes: 6
Reputation: 29846
Simply use a comma to do that:
$(document).on('click', '.SELECTOR1, #SELECTOR2', function(){
// some code
});
Upvotes: 5