click method

This topic has not yet been rated - Rate this topic

Simulates a click by causing the onclick event to fire.

Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5

Syntax

object.click()

Parameters

This method has no parameters.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Standards information

Remarks

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

Examples

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


<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <p>DEMO: USING CLICK METHOD DOES NOT SET FOCUS<p>
    <ul>
      <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.</li> 
    </ul>
  </p>
  <input type="checkbox" id="chk1"/>	
    <br>
    <button onclick="simclick1()">This button <strong>applies the focus method</strong> to 
      check box</button>
    <br>
    <button onclick="simclick2()">This button <strong>does not apply the focus method</strong> to check box</button>
    <br>

  <script type="text/javascript">
	// When chk1 gets focus, pop an alert
	document.getElementById("chk1").addEventListener("focus", function(){console.log("check box is in focus!");}, false);
    function simclick1() {
      chk1.focus(); //focus is explicitly set
      chk1.click(); 
    }
    function simclick2() {
      chk1.click();
    }
  </script>
</body>
</html>


See also

a
abbr
address
area
article
aside
b
bdo
blockQuote
body
br
button
caption
cite
code
col
colGroup
custom
dd
del
div
dl
dt
em
embed
fieldSet
figcaption
figure
footer
form
head
header
hgroup
hn
hr
html
i
iframe
img
input type=button
input type=checkbox
input type=file
input type=hidden
input type=image
input type=password
input type=radio
input type=reset
input type=submit
input type=text
ins
kbd
label
legend
li
map
mark
nav
object
ol
optGroup
option
p
pre
q
rt
ruby
s
samp
section
select
small
span
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
tr
u
ul
var

 

 

Build date: 11/28/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.