I know I can use $.each to apply the same event handler to two different jQuery objects. I'm surprised it was not possible to have a cleaner syntax such as:
var $span = $('span');
var $div = $('div');
var clickHandler = function () {
$(this).toggleClass('red');
}
$($span, $div).on('click', clickHandler); // <-- Neater syntax
$([$span, $div]).on('click', clickHandler); // <-- A little worse, but still better than $.each
Why do the syntaxes I have tried not work? Is there a neater alternative to using $.each?