I have several objects to whom I would like to attach the same event handler. So far, I’m doing this:
$(object).bind(event, function(event) {
// Code
});
$(object2).bind(event, function(event) {
// Same code
});
$(object3).bind(event, function(event) {
// Same code again
});
I know there’s nothing wrong with this approach (or is there), but I’m wondering if there’s a shorthand method for binding the same handler for the same event to several different objects.
EDIT: what I mean is, instead of writing object1.bind(stuff); object2.bind(stuff); object3.bind(stuff); etc I want something like allObjects.bind(stuff).
How about,
Note: Assuming the
object1is selector string.