Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

click

Summary

Covers what the click action is and what happens when it is performed.

Method of dom/HTMLElementdom/HTMLElement

Syntax

var object = object.click();

Return Value

Returns an object of type DOM NodeDOM Node

Type: HRESULT

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

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>
<title>onfocus Sample</title>
<link rel="stylesheet" type="text/css" href="samplesSDKIE4.css" />
</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>
    // When chk1 gets focus, pop an alert
    document.getElementById("chk1").addEventListener("focus", function(){alert("check box is in focus!");}, false);
    function simclick1() {
      chk1.focus(); //focus is explicitly set
      chk1.click();
    }
    function simclick2() {
      chk1.click();
    }
  </script>
</body>
</html>

View live example

Notes

Remarks

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

Syntax

Standards information

Attributions