Thursday, August 8, 2013

Event listener for few elements at once

Event listener for few elements at once

Is there a way to add listener for few elements at once?
What I'm doing currently is
$('#test1').on('click', function(event) {
doSomething();
});
$('#test2').on('click', function(event) {
doSomething();
});
$('#test3').on('click', function(event) {
doSomething();
});
As you can see, all three IDs are triggering the same function. How can I
combine the code so I won't need to copy code for each listener?

No comments:

Post a Comment