jQuery Action Event

jQuery Action adds a new event to jQuery called "action", which is simply the equivalent of either a mouse click or pressing the enter key on a given element.


Click on the button, press enter, then try middle clicks, shift+click, alt+enter to see if the user intended a 'primary' action or not.

Download from Github (requires jQuery 1.3.2+
-earlier versions may work too!)

What's it for?

Well instead of assigning clicks to everything, I wanted a simple way for users to also be able to tab through content and to fire events with a simple press of enter. jQuery (Focus) Enter and Leave Events also help out in with combined mouse/keyboard interactions.


jQueryObject.bind('action', [ eventData ], handler(eventObject) )

Bind an event handler to the special event "action", or trigger that event on an element. Returns jQuery.

eventData A map of data that will be passed to the event handler. See options below.

handler(eventObject) A function to execute each time the event is triggered.

The primary property of the eventObject indicates whether the user intended for the action to primary (true) or secondary (false). In more details, this means eventObject.primary is true for a simple left click or enter keypress, and false if the middle mouse button is used or if, during the action, a meta key, ctrl, shift or alt key was held down. This can essentially help developers determine whether the user intended for the action to take place on the same page or on a new page (or some other similar intention).

Note right clicks are not caught.

eventData options

The property autotab in eventData is Boolean and if true, it will make any elements that the action event is attached to appear in the tab flow (if not already).

No shortcut method

This event works with jQuery functions such as jQuery.bind() .one() and so on. A shortcut method has not been added e.g. there is no .action()

handler return value

Unfortunately, if the action event is triggered by a click, the return value of the handler is ignored.

◂ Back to the code section