var $obj1 = $('a#one');
var $obj2 = $('a#two');
var $obj3 = $('a#three');
// Assume $('a#one, a#two, a#three') wasn't an option.
How do I assign one (same) event handler e.g. click() to those three jQuery objects? Essentially, I am looking for a more efficient way of doing:
$obj1.click(function() { /* Code A */ });
$obj2.click(function() { /* Code A */ });
$obj3.click(function() { /* Code A */ });
Only (very) marginally shorter, but:
You would want to define your handler outside of the first anonymous function though, so you’d really probably be better off with Jonas H’s method. Just throwing another suggestion out there.
Note: you could technically do a hybrid, but it’s quite lengthy:
Really this question is only useful if you want to avoid the $a.click(f) over and over again, which is truly a better option than this jQuery abuse. 🙂