tags:

views:

281

answers:

2

Hello, is there any way to execute same code for different elements on the page?

$('.class1').click(function() {
   some_function();
});

$('.class2').click(function() {
   some_function();
});

instead to do something like:

$('.class1').$('.class2').click(function() {
   some_function();
});

Thanks

+3  A: 
$('.class1, .class2').click(some_function);

Or:

$('.class1').add('.class2').click(some_function);
Eevee
+1  A: 

Simply use $('.myclass1,.myclass2,.myclass3') for multiple selectors. Also, you dont need lambda functions to bind an existing function to the click event.

code_burgar