click method
Simulates a mouse click on the current element.
Simulating a click event on an element with the click method causes the default action of the event to be performed, but the element does not get the focus.
For example, invoking the click method on a checkbox toggles its checked state, invoking the click method on an input field does not cause the input field to get the focus.
- If you need to simulate other events, see the page for the dispatchEvent and fireEvent methods.
- To set or remove the focus from an element, use the focus and blur methods.
- In Internet Explorer, if you want to simulate a mouse click on a scrollbar component of an element, use the doScroll method.
Syntax:
You can find the related objects in the Supported by objects section below.
Return value:
This method has no return value.
Example HTML code 1:
This example illustrates the use of the click method:
|
||||
<head> <script type="text/javascript"> function InitClick (checkbox) { checkbox.click (); } </script> </head> <body> <input type="checkbox" onmouseover="InitClick (this);" onclick="alert ('click event occurred')"/>Hover over the check box! </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
HTML elements:
a, abbr, acronym, address, applet, area, b, bdo, big, blockquote, body, button, caption, center, cite, code, col, colgroup, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, label, legend, li, listing, map, marquee, menu, nobr, noframes, object, ol, option, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
External links:
User Contributed Comments