Friday, April 27, 2012

jquery .click pass parameters to user function

Method 1:
$('.myclass').bind("click", { Param1: "", Param2: 2 }, function(event){
    alert(event.data.Param2);
});

Method 2:
// say your selector and click handler looks something like this...
$("some selector").click({param1: "Hello", param2: "World"}, cool_function);

// in your function, just grab the event object and go crazy...
function cool_function(event){
    alert(event.data.param1);
    alert(event.data.param2);
}

Reference:
http://stackoverflow.com/questions/3273350/jquery-click-pass-parameters-to-user-function
http://stackoverflow.com/questions/1541127/how-to-send-multiple-arguments-to-jquery-click-function

No comments: