Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mattConn
Last active November 22, 2016 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattConn/1db57d43685476a9378b144175d617b7 to your computer and use it in GitHub Desktop.
Save mattConn/1db57d43685476a9378b144175d617b7 to your computer and use it in GitHub Desktop.
JQuery switch statement for key binding.
$(document).keyup(function(e) { //keydown can be used as well.
switch(e.which) {
case 37: //left; any keycode can be used for each case.
alert('keycode: '+e.which);
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
@mattConn
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment