I was using jQuery live() function to detect when the user was pressing some special keys (arrows, etc.):
$('.TextBox1').live('keydown', function(e) {
var keyCode = e.keyCode || e.which;
if (keyCode == 40) {
e.preventDefault();
// ...
}
});
It was working fine for a couple of months when suddenly yesterday it stopped working, preventing every line of JS code below it from executing. I have tried to replace it with the .keyup function but this has not helped. What could have happened?
I assume you’ve updated to the latest version of jQuery?
live()has been deprecated since jQ1.7, and is now removed as of 1.9.Instead, you should use
on()with a delegate parameter:Note that for best performance you should replace
documentin the above example with the closest parent element of.TextBox1which is not dynamically appended to the DOM after page load.