views:

29

answers:

2

Hi,

This is how to bind multiple events on a couple jQuery selectors:

$('#selector1,.selector2').bind('event', function (e, ui) {
   // Stuff
});

But! How do you bind on predeclared jQuery objects. Example:

var jSelector1 = $('#selector1');
var jSelector2 = $('.selector2');

Because, the following doesn't work:

jSelector1,jSelector2.bind(...);

nor does:

$jSelector1,$jSelector2.bind(...);
($jSelector1,$jSelector2).bind(...);
(jSelector1,jSelector2).bind(...);
+1  A: 

This should work, assuming your variables hold jQuery objects

$.each([jSelector1, jSelector2], function(i,v) {

    v.bind( ... );

});
Russ Cam
damn you beat me to it
Falle1234
@Falle1234 - great minds :)
Russ Cam
worked perfectly! many thanks!
Emile
happy to help :)
Russ Cam
+1  A: 

you should be able to do something like this:

var jSelector1 = $('#selector1');
var jSelector2 = $('.selector2');

$.each([jSelector1, jSelector2], function(index, value) { 
  value.bind(....); 
});
Falle1234
4 mins! damn. thanks though! this works too :)
Emile