HTMLElement.click()

  • Revision slug: DOM/element.click
  • Revision title: element.click
  • Revision id: 332571
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment

Revision Content

{{DomRef}}

Summary

The click method simulates a mouse click on an element.

Syntax

element.click()

Notes

{{gecko_callout_heading("5.0")}}

Prior to Gecko 5.0 {{geckoRelease("5.0")}}, Gecko didn't implement the click method on other elements that might be expected to respond to mouse–clicks such as links (A elements), nor will it necessarily fire the click event of other elements. However, now it is supported by all elements, as required by HTML5.

Non–Gecko DOMs may behave differently.

When a click is used with elements that support it (e.g. one of the {{HTMLElement("input")}} types listed above), it also fires the element's click event which will bubble up to elements higher up the document tree (or event chain) and fire their click events too. However, bubbling of a click event will not cause an A element to initiate navigation as if a real mouse-click had been received.

By the time of this writting (Opera Next is in version 12.11), Opera's click() method will silentely be ignored if made on an {{HTMLElement("input")}} with its "type" attribute set to "file" and its CSS display property set to "none".

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Minimum support {{CompatVersionUnknown}} 5 {{CompatNo}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
input@file (limited) {{CompatVersionUnknown}} 4 {{CompatNo}} 12.10 {{CompatVersionUnknown}}
input@file (full) {{CompatVersionUnknown}} 4 {{CompatNo}} {{CompatNo}} {{CompatVersionUnknown}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

Note: Basic support here, is to support just the barely minimum that the specification forces the browser to support.

Specification

Revision Source

<div>{{DomRef}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>The <strong>click</strong> method simulates a mouse click on an element.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">element.click()</pre>
<h2 id="Notes" name="Notes">Notes</h2>
<div class="geckoVersionNote">
  <p>{{gecko_callout_heading("5.0")}}</p>
  <p>Prior to Gecko 5.0 {{geckoRelease("5.0")}}, Gecko didn't implement the click method on other elements that might be expected to respond to mouse–clicks such as links (A elements), nor will it necessarily fire the click event of other elements. However, now it is supported by all elements, as required by&nbsp;HTML5.</p>
  <p>Non–Gecko DOMs may behave differently.</p>
</div>
<p>When a click is used with elements that support it (e.g. one of the {{HTMLElement("input")}} types listed above), it also fires the element's click event which will bubble up to elements higher up the document tree (or event chain) and fire their click events too. However, bubbling of a click event will not cause an A element to initiate navigation as if a real mouse-click had been received.</p>
<p>By the time of this writting (Opera Next is in version 12.11), Opera's click() method <strong>will silentely be ignored</strong> if made on an {{HTMLElement("input")}} with its "type" attribute set to "file" and its CSS display property set to "none".</p>
<h2 id="Browser_Compatibility" name="Browser_Compatibility">Browser compatibility</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari (WebKit)</th>
      </tr>
      <tr>
        <td>Minimum support</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>5</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
      <tr>
        <td><code>input@file (limited)</code></td>
        <td>{{CompatVersionUnknown}}</td>
        <td>4</td>
        <td>{{CompatNo}}</td>
        <td>12.10</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
      <tr>
        <td><code>input@file (full)</code></td>
        <td>{{CompatVersionUnknown}}</td>
        <td>4</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatNo}}</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Chrome for Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
  
<p>Note: Basic support here, is to support just the barely minimum that the specification forces the browser to support.</p>

<h2 id="Specification" name="Specification">Specification</h2>
<ul>
<li><a class="external" href="http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-2651361">click</a></li>
</ul>
Revert to this revision