mkoryak
mkoryak

Reputation: 57968

jQuery binding multiple events, and pass data

I know we can have this in 1.4:

$("a").bind({
  click : clickFn,
  mouseover: mouseFn
});

and that is nice and I would like to use it, but it seems like there is no way to pass extra data to events bound this way, it needs to be done the 'old way':

$("a").bind("click", {"some":"data"}, clickFn);

Question:
How can I pass the extra data to my event call backs and bind multiple events in a single bind at the same time?

Upvotes: 1

Views: 860

Answers (1)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196197

You could do something like

$("a").bind({
  click : function() { clickFn.apply(this, [param1,param2,..]); },
  mouseover: function() { mouseFn.apply(this, [param1,param2,..]); }
});

although you would need to make your functions accept parameters in this way ..

[made an update to maintain context]

Upvotes: 3

Related Questions