Developer Checklist — JavaScript Appendices

Correct code

JS_C_A2: Use the click event of links and buttons as an activation event

The click event is the most device-independent event we have. All JavaScript-capable browsers and devices have a means of firing click events, which might be (among others): clicking with the mouse, pressing Enter with the keyboard, touching a touch-screen interface, pressing the Fire button on a Sony PSP, pressing the OK button on a Web-TV remote, or nodding in front of a head-gesture recognition interface.

The click event can be thought of as the canonical activation event, because it always require an explicit user action. By contrast, events like focus or mouseover are merely tangential to the actions that trigger them, so they should not be used as activation events.

Live Demo

Activate the button below and its click event will fire:

JavaScript Code

The JavaScript code for this example can be found in: JS_C_A2.js