click method

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
acronym
address
applet
area
article
aside
b
bdo
big
blockQuote
body
br
button
caption
center
cite
code
col
colGroup
custom
dd
del
dfn
dir
div
dl
dt
em
embed
fieldSet
figcaption
figure
font
footer
form
frame
frameSet
head
header
hgroup
hn
hr
html
i
iframe
img
input type=button
input type=checkbox
input type=email
input type=file
input type=hidden
input type=image
input type=number
input type=password
input type=radio
input type=range
input type=reset
input type=search
input type=submit
input type=tel
input type=text
input type=url
ins
isIndex
kbd
label
legend
li
listing
map
mark
marquee
menu
nav
nextID
noBR
object
ol
optGroup
option
p
plainText
pre
q
rt
ruby
s
samp
section
select
small
span
strike
strong
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
tr
tt
u
ul
var
xmp

 

 

Show:
© 2014 Microsoft