Last active
August 29, 2015 14:10
-
-
Save acdcjunior/b88f2a355f51584121c9 to your computer and use it in GitHub Desktop.
Creating (binding) a specific event and removing (unbinding) it only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on("keyup.escKeyClosesModal", function(e) { ... }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).off("keyup.escKeyClosesModal"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function letESCKeyCloseMyModal() { | |
$(document).on("keyup", function(e) { | |
if (e.keyCode === 27) { // ESC key | |
closeMyModal(); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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