Skip to content

Instantly share code, notes, and snippets.

@acdcjunior
Last active August 29, 2015 14:10
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 acdcjunior/b88f2a355f51584121c9 to your computer and use it in GitHub Desktop.
Save acdcjunior/b88f2a355f51584121c9 to your computer and use it in GitHub Desktop.
Creating (binding) a specific event and removing (unbinding) it only
$(document).on("keyup.escKeyClosesModal", function(e) { ... });
$(document).off("keyup.escKeyClosesModal");
function letESCKeyCloseMyModal() {
$(document).on("keyup", function(e) {
if (e.keyCode === 27) { // ESC key
closeMyModal();
}
});
}
function closeMyModal() {
$("#myModal").dialog("close"); // closes the modal
$(document).off("keyup"); // removes ESC key bind
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment