jQuery bind and unbind event with parameters

Paul Knopf picture Paul Knopf · Nov 17, 2009 · Viewed 13.9k times · Source

I am trying to bind an event to a textbox that contains parameters. The following keep looks as if it should do it, but every time the page loads, it gets executed.

jQuery(function(){
    jQuery('#textbox').bind('click', EventWithParam('param'));
});

The event gets called with that parameter every time the page loads. This may not work because events with parameters are not supported. If so, is there another route?

Answer

jsonx picture jsonx · Jan 11, 2010

You can pass event parameters as second arguments to bind(). It is not direct callback parametes but maybe you would like to use it:

From jQuery documentation: bind

function handler(event) {
    alert(event.data.foo);
}  
$("p").bind("click", {foo: "bar"}, handler)