Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Bind a function to escape keypress
# $.esc
# Binds the given callback function to the keyup
# event for the "Escape" key
# Example usage:
# $.esc(function(event) {
# alert("Escape key pressed!");
# });
# Compatible with jQuery or Zepto
$.esc = (callback) ->
$(document).on 'keyup', (event) ->
callback?(event) if event.keyCode is 27

This comment has been minimized.

Copy link
Owner Author

@paulspringett paulspringett commented May 1, 2012

Example use:

$.esc(function(event) {
  alert("Escape key pressed!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment