Skip to content

Instantly share code, notes, and snippets.

@jbuncle
Created July 1, 2016 08:49
Show Gist options
  • Save jbuncle/90701499a52e2081a6bd59f62947f580 to your computer and use it in GitHub Desktop.
Save jbuncle/90701499a52e2081a6bd59f62947f580 to your computer and use it in GitHub Desktop.
Basic jQuery function for handling enter key being hit.
/**
* Basic jQuery function for handling enter key being hit.
*
* @returns jQuery
*/
$.fn.onEnterKeypress = function (callback) {
return $(this).keypress(function (evt) {
// Check for enter key
if (evt.which === 13) {
// Invoke callback
callback.call(this, evt);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment