onclick | NN 2 IE 3 DOM 2
| Bubbles: Yes; Cancelable: Yes
Fires after the user effects a mouse click or equivalent action. Click equivalents occur naturally on focusable elements (buttons and links for most browsers) by pressing the Enter key (and frequently the spacebar) when the item has focus. In modern browsers that support the accesskey attribute, typing the access key combination also triggers a click equivalent.
For mouse click actions, the onclick event fires only if the mouse button is pressed and released with the pointer atop the same element. In that case, the primary mouse events fire in this order: onmousedown, onmouseup, and onclick.
An event object created from a mouse event has numerous properties filled with details such as coordinates of the click and whether any modifier keys were held down during the event. Information about the button used is more reliably accessed through the onmousedown or onmouseup events. The event handler function can inspect these properties as needed.
Although the onclick event has been supported for button-oriented form controls and link objects since the early days of scriptable browsers, modern browsers can fire the event on virtually any other rendered element. Note that in Netscape 6, mouse events can fire on child text nodes of container-type elements, meaning that the event object's target property references the node, rather than the element. See Chapter 6 for details about the impact of this W3C DOM-endorsed behavior and cross-browser solutions.
Typical Targets
For all browsers, input (of type button, radio, checkbox, reset, and submit), a, and area objects; Version 4 and later support the event for the document and window objects; for IE 4 or later and Netscape 6, add any rendered element, as well as text nodes for Netscape 6.