$(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.
$(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.
Share Improve this question asked Apr 15, 2015 at 15:40 StevikStevik 1,1522 gold badges17 silver badges38 bronze badges 1-
write like this
'.SELECTOR1, #SELECTOR2'
use a – Nishit Maheta Commented Apr 15, 2015 at 15:41
2 Answers
Reset to default 6The 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 ma to do that:
$(document).on('click', '.SELECTOR1, #SELECTOR2', function(){
// some code
});
JSFIDDLE.