Fires when the user clicks the left mouse button on the object.
If the event bubbles and is cancellable, return VARIANT_TRUE to prevent the event from bubbling to other event handlers in the document tree. Return VARIANT_FALSE to allow bubbling.
The DISPID for this event is defined in mshtmdid.h. Use this value to identify the event handler when implementing IDispatch::Invoke.
Bubbles Yes Cancels Yes To invoke
- Click the object.
- Invoke the IHTMLElement::click method.
- Press the ENTER key in a form.
- Press the access key for a control.
- Select an item in a combo box or list box by clicking the left mouse button or by pressing the arrow keys and then pressing the ENTER key.
Default action Initiates any action associated with the object. For example, if the user clicks an a object, the client loads the document specified by the IHTMLAnchorElement::href property. To cancel the default behavior, set the returnValue property of the event object to FALSE.
If the user clicks the left mouse button, the HTMLButtonElementEvents::onclick event for an object occurs only if the mouse pointer is over the object and an HTMLButtonElementEvents::onmousedown and an HTMLButtonElementEvents::onmouseup event occur in that order. For example, if the user clicks the mouse on the object but moves the mouse pointer away from the object before releasing, no HTMLButtonElementEvents::onclick event occurs.
The HTMLButtonElementEvents::onclick event changes the value of a control in a group. This change initiates the event for the group, not for the individual control. For example, if the user clicks a radio button or check box in a group, the HTMLButtonElementEvents::onclick event occurs after the onbeforeupdate and onafterupdate events for the control group.
If the user clicks an object that can receive the input focus but does not already have the focus, the onfocus event occurs for that object before the HTMLButtonElementEvents::onclick event. If the user double-clicks the left mouse button in a control, an HTMLButtonElementEvents::ondblclick event occurs immediately after the HTMLButtonElementEvents::onclick event.
Although the HTMLButtonElementEvents::onclick event is available on a large number of HTML elements, if a document is to be accessible to keyboard users, you should restrict its use to the a, input, area, and button elements. These elements automatically allow keyboard access through the TAB key, making documents that use the elements accessible to keyboard users. For more information, please see the section on writing accessible Dynamic HTML.