Javascript - multiple selector

$(document).on('click', '.SELECTOR1 OR #SELECTOR2', function(){ // some code }); 

What I want to achieve is to run some code by clicking on one of the elements.

+5
source share
2 answers

The Sizzle selection engine used by jQuery follows the same rules as CSS. With this in mind, you can separate the selectors with,:

 $(document).on('click', '.SELECTOR1, #SELECTOR2', function(){ // some code }); 
+6
source

Just use a comma to do this:

 $(document).on('click', '.SELECTOR1, #SELECTOR2', function(){ // some code }); 

JSFIDDLE .

+5
source

All Articles