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
Another alternative, assuming your elements are stored as variables (which is often a good idea if you're accessing them multiple times in a function body):
Takes advantage of jQuery chaining and allows you to use references.
Add a comma separated list of classes like this :
In addition to the excellent examples and answers above, you can also do a "find" for two different elements using their classes. For example:
This should output "HelloWorld".