onClick (Event handler)

This event is triggered when the user clicks the mouse button with the pointer over the Element object that represents the object on screen.

Availability:

HTML version - 4.0
JavaScript - 1.0
JScript - 1.0
Internet Explorer - 3.0
Netscape - 2.0
Opera - 3.0
Property/method value type:Boolean primitive
JavaScript syntax:-myObject.onclick = aHandler
HTML syntax:<A onClick="..."> <AREA onClick="..."> <HTMLTag onClick="..."> <INPUT onClick="...">
Argument list:aHandlerA reference to a function object to handle the event
Supported by objects:A, ACRONYM, ADDRESS, Anchor, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, Checkbox, CITE, CODE, DD, DEL, DFN, DIR, DIV, DL, Document, DT, EM, FIELDSET, FileUpload, FONT, FORM, H1, HR, I, IMG, Input, INS, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, OBJECT, OL, P, Password, PLAINTEXT, PRE, Q, RadioButton, ResetButton, S, SAMP, Select, SMALL, SPAN, STRIKE, STRONG, SUB, SubmitButton, SUP, TABLE, TBODY, TD, TEXTAREA, TextCell, TFOOT, TH, THEAD, TR, TT, U, UL, Url, VAR

The onClick event handler is invoked when the user clicks once on the object that it belongs to. This might normally be a hypertext link. As of version 1.1 of JavaScript, if the handler returns the Boolean false value then the browser will not follow the link to its HREF. If a true value is returned then it will.

This event applies to anchors, reset buttons, and submit buttons. A false return value inhibits the browser from taking any default actions once your handler is completed.

Netscape indicates which mouse button was pressed in the which property of the Event object that is passed as an argument to the event handler function. MSIE makes the value available in the button property of the Event object referenced by the window.event property.

DOM level 2 refers to this as a DOMActivate event, which employs event bubbling for its propagation and can be canceled. The context info provides detail about whether its was a single or double click.

DOM level 2 also classifies this as a MouseEvent and specifies that it must follow a matching pair of mousedown and mouseup events without any intervening mouse movement. As a MouseEvent it uses bubbling propagation and can be canceled.

Warnings:

See also:Button object, BUTTON object, Checkbox object, Element object, Element.click(), Event, Event handler, Event model, Event names, Event object, Event.button, Event.returnValue, Event.which, Handler, Input.click(), Mouse events, MouseEvent object, RadioButton object, ResetButton object, Semantic event, SubmitButton object, UIEvent object