Using bind (type, [data], fn) and non-inline function
3 answers
Your problem is that you are giving it an argument that causes the function to execute and the return value is replaced as the argument for the binding. What you want to do is just provide a reference to the function as an argument for the binding. Do this, leaving out the parentheses (and the argument). The arguments supplied by the binding to the callback must be included in the function definition.
$("p").bind("click", myFunction);
function myFunction(event) {
// code goes here
}
+2
a source to share