You need to pass the function as an argument. You pass the return value of the called function
function myFunction(text){ alert(text); } $('#input1').on({ keyup: function(){myFunction('keyup');}, blur: function(){myFunction('blur');}, focus: function(){console.log('focus!');} });
Or you can convert myFunction to a function generator
function myFunction(text){ return function(){ console.log(text); } } $('#input1').on({ keyup: myFunction('keyup'), blur: myFunction('blur'), focus: function(){console.log('focus!');} });
Demo at http://jsfiddle.net/gaby/GrMQX/6/
Gaby aka G. petrioli
source share