Problem:
The blur
and keyup
events each fire once onload, and only onload. How can I get them to work correctly?
jQuery:
function myFunction(text){
alert(text);
}
$('#input1').on({
keyup: myFunction('keyup'),
blur: myFunction('blur'),
focus: function(){console.log('focus!');}
});
Fiddle: http://jsfiddle.net/GrMQX/
You need to pass a function as an argument.. you are passing the return value of the called function
Or you can convert your
myFunction
to a function generatorDemo at http://jsfiddle.net/gaby/GrMQX/6/
You are not assigning a function to
keyup
andblur
, you're assigning the result of the execution ofmyFunction
.Change it like this:
DEMO
You're not declaring the functions as callbacks, you're executing them and their return result is assigned as a callback (which doens't work).
Try this:
use with .on() Event
You're actually executing the functions when you call them that way. Try this:
jsFiddle example