I have 3 jquery objects:
var a = $('.el1');
var b = $('.el2');
var c = $('.el3');
And I want to bind a "change" event to all of them at once, but I can't :(
$(a, b, c).bind('paste input change', function(){ ... });
simply doesn't work...
But if bind it to each element separately it works:
a.bind('...');
b.bind('...');
c.bind('...');
Is it possible to do this in a shorter way?
(And without passing the classes as selectors)
Use .add()
[docs]:
a.add(b).add(c).bind(...
$([a,b,c]).bind should work, as in:
var a = $('.el1');
var b = $('.el2');
var c = $('.el3');
$([a,b,c]).each(function(idx){
$(this).bind('click', function(){
alert($(this).text());
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With