When I have
$('#div').click(function(someVar){//do something with soneVar});
but I want to have a named callback function, am I palcing the passed someVar
correctly?
$('#div').click(someFunction(someVar));
function someFunction(someVar){}
Both of your examples are wrong.
Your first example creates a parameter to the callback method named someVar
; it will become the event
object that jQuery passes to the handler method.
The second example calls the method immediately, then passes its result to the click
method as an event handler.
You you need to pass a function expression that calls your function with a parameter from the outer scope (using a closure):
$('#div').click(function() { someFunction(someVar); });
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