5

I have two classes: Class1 and Class2.

For now, I have 2 function calls calling the same MyFunction function:

$('.Class1').click(function () { MyFunction() });
$('.Class2').click(function () { MyFunction() });

How do I rewrite this to say "when there's a click on Class1 and on Class2 call MyFunction".

Thanks.

2
  • 1
    AND or OR ? Clearly you cannot click to objects at the same time. Commented Jan 25, 2011 at 19:05
  • Do you mean "or" when you say "when there's a click on Class1 and on Class2 call MyFunction". Commented Jan 25, 2011 at 19:06

2 Answers 2

19
$('.Class1, .Class2').click(function () { MyFunction() })
Sign up to request clarification or add additional context in comments.

Comments

3

to bind a click event to 2 different classes

$('.Class1, .Class2').click()

this would mean if Class1 OR Class2 is clicked, fire the event.

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.