Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Jquery plugin to simulate an event that is binded to the enter key
* Jquery enter event plugin.
* It will intercept keypress events but only call the handlers
* if the pressed key is Enter
* Events can be binded with the 'enter' event type or the enter function
* The function accepts an option data parameter tha will be passes to the handler function
* and an event handler. If called without parameters it will trigger the event.
jQuery.event.special.enter = {
bindType: "keypress",
delegateType: "keypress",
handle: function(event, data){
if (event.which == 13 || !event.originalEvent){
return event.handleObj.handler(event, data);
jQuery.fn.enter = function( data, fn ) {
return arguments.length > 0 ? this.on('enter', null, data, fn ) : this.trigger('enter');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.