<p>The event handler can be bound to any <code><div></code>:</p>
<pre>$('#target').dblclick(function() {
alert('Handler for .dblclick() called.');
});</pre>
<p>Now if we double-click on this element, the alert is displayed:</p>
<p><spanclass="output">Handler for .dblclick() called.</span></p>
<p>We can also trigger the event when a different element is clicked:</p>
<pre>$('#other').click(function() {
$('#target').dblclick();
});</pre>
<p>After this code executes, (single) clicks on <spanclass="output">Trigger the handler</span> will also alert the message.</p>
<p>The <code>dblclick</code> event is only triggered after this exact series of events:</p>
<ul>
<li>The mouse button is depressed while the pointer is inside the element.</li>
<li>The mouse button is released while the pointer is inside the element.</li>
<li>The mouse button is depressed again while the pointer is inside the element, within a time window that is system-dependent.</li>
<li>The mouse button is released while the pointer is inside the element.</li>
</ul>
<p>It is inadvisable to bind handlers to both the <code>click</code> and <code>dblclick</code> events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two <code>click</code> events and others only one. If an interface that reacts differently to single- and double-clicks cannot be avoided, then the <code>dblclick</code> event should be simulated within the <code>click</code> handler. We can achieve this by saving a timestamp in the handler, and then comparing the current time to the saved timestamp on subsequent clicks. If the difference is small enough, we can treat the click as a double-click.
</p>
</div>
<h3>Examples:</h3>
<divid="entry-examples"class="entry-examples">
<divid="example-0">
<h4>Example: <spanclass="desc">To bind a "Hello World!" alert box the dblclick event on every paragraph on the page:</span>
</h4>
<pre><codeclass="example">$("p").dblclick( function () { alert("Hello World!"); });</code></pre>
</div>
<divid="example-1">
<h4>Example: <spanclass="desc">Double click to toggle background color.</span>