Availability: |
| |||||||
Property/method value type: | Boolean primitive | |||||||
JavaScript syntax: | - | myObject.onclick = aHandler | ||||||
HTML syntax: | <A onClick="..."> <AREA onClick="..."> <HTMLTag onClick="..."> <INPUT onClick="..."> | |||||||
Argument list: | aHandler | A 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.
When you add an onClick handler to an <A> tag object, MSIE and Netscape execute the click in the same way but modify the browser history differently.
An onClick event will also generate an onMouseDown event and an onMouseUp event. The onClick will not be triggered until the onMouseUp event. There is no guarantee that the onClick event will arrive after the onMouseUp event although that is the logical order.
Prev | Home | Next |
onChange | Up | onContentReady |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |