click Method

Internet Development Index

Simulates a click by causing the onclick event to fire.

Syntax

object.click()

Return Value

No return value.

Remarks

Note  Simulating a click using the click does not bring the element being clicked into focus. (See example below).

Example

The following example demonstrates how simulating a click using the click does not, by default, bring the element into focus.

<HTML>
<HEAD>
<SCRIPT>
function simclick1()
{
chk1.focus(); //focus is explicitly set
chk1.click();
}
function simclick2()
{
chk1.click();
}
</SCRIPT>
<SCRIPT FOR=chk1 EVENT=onfocus>
alert("check box is in focus!");
</SCRIPT>
</HEAD>
<BODY>
<P STYLE="font-family:sans-serif;font-weight:bold">DEMO: USING CLICK METHOD
DOES NOT SET FOCUS<P>
<UL STYLE="color:blue;font-family:sans-serif;font-weight:bold">
<LI>Both these buttons apply the click method to the check box. </LI>
<LI>An alert has been set to fire when the check box is put into focus.
</UL>
</PLI>
<INPUT Type="CHECKBOX" id=chk1></INPUT>
<br>
<BUTTON onclick="simclick1()">This button <B>applies the focus method</B> to
check box</BUTTON>
<br><BUTTON onclick="simclick2()">This button <B>does not apply the focus
method</B> to check box</BUTTON>
<br>
</BODY>
</HTML>
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Standards Information

This method is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 Non-Microsoft link.

Applies To

A, ADDRESS, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, CUSTOM, DD, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, hn, HR, I, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, NOBR, OBJECT, OL, OPTION, P, PLAINTEXT, PRE, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP