Skip to content

Instantly share code, notes, and snippets.

@enopanen
Created December 3, 2013 18:04
Show Gist options
  • Save enopanen/7774263 to your computer and use it in GitHub Desktop.
Save enopanen/7774263 to your computer and use it in GitHub Desktop.
Dealing with user input is another grey area I have come across. The jQuery keydown and keyup event listeners are perfect for dealing with such experiences. Both of these methods are called at very different times during the keystroke event. So make sure you have the application planned out before deciding which one to use.
$('input').keydown(function(e) {
// variable e contains keystroke data
// only accessible with .keydown()
if(e.which == 11) {
e.preventDefault();
}
});
$('input').keyup(function(event) {
// run other event codes here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment