Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery binding same event to 2 selectors

Tags:

jquery

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.

like image 761
frenchie Avatar asked Jan 25 '11 19:01

frenchie


2 Answers

$('.Class1, .Class2').click(function () { MyFunction() })
like image 69
Attila Kun Avatar answered Oct 14 '22 23:10

Attila Kun


to bind a click event to 2 different classes

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

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

like image 3
jondavidjohn Avatar answered Oct 14 '22 23:10

jondavidjohn