So say I have this ..
keyup_handler: function(e, item){
if (e.which == 27) {
close_lightbox(item);
return false;
};
}
$(document).live('keyup', function(e){ keyup_handler(e, item) });
This is not returning any console.log()’s I place in here. So I assume that that it’s not being touched. What am I missing? How do I pass the e or event to keyup_handler?
jQuery 1.4.4
You’re returning
falsefrom the call tokeyup_handler, but not from the function that calls it, try doing:You may also need to modify
keyup_handlerslightly toreturn true;if theifstatement doesn’t evaluate to true.I’m assuming here that your very vague “doesn’t work” statement means that the usual keyup functionality isn’t prevented when you release the corresponding key.
Also,
.live()is a deprecated jQuery function, and isn’t really intended for what you’re using it for. Use.on()(if you’re using jQuery 1.7+) or.bind()otherwise.