5
$(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.

1
  • write like this '.SELECTOR1, #SELECTOR2' use coma Commented Apr 15, 2015 at 15:41

2 Answers 2

6

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
});
Sign up to request clarification or add additional context in comments.

Comments

5

Simply use a comma to do that:

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

JSFIDDLE.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.