.dblclick()

Bind an event handler to the "dblclick" JavaScript event, or trigger that event on an element.

.dblclick(function(eventObjectEvent))🡢 jQuery

function(eventObjectEvent) FunctionA function to execute each time the event is triggered.

.dblclick(eventData, function(eventObjectEvent))🡢 jQuery

eventData AnythingAn object containing data that will be passed to the event handler.
function(eventObjectEvent) FunctionA function to execute each time the event is triggered.

.dblclick()🡢 jQuery

This method is a shortcut for .on( "dblclick", handler ) in the first two variations, and .trigger( "dblclick" ) in the third. The dblclick event is sent to an element when the element is double-clicked. Any HTML element can receive this event. For example, consider the HTML:

<div id="target">Double-click here</div>
<div id="other">Trigger the handler</div>
Figure 1 - Illustration of the rendered HTML

The event handler can be bound to any <div>:

$("#target").dblclick(function () {
  alert("Handler for .dblclick() called.");
});

Now double-clicking on this element displays the alert:

Handler for .dblclick() called.

To trigger the event manually, call .dblclick() without an argument:

$("#other").click(function () {
  $("#target").dblclick();
});

After this code executes, (single) clicks on Trigger the handler will also alert the message.

The dblclick event is only triggered after this exact series of events:

  • The mouse button is depressed while the pointer is inside the element.
  • The mouse button is released while the pointer is inside the element.
  • The mouse button is depressed again while the pointer is inside the element, within a time window that is system-dependent.
  • The mouse button is released while the pointer is inside the element.

It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events before the dblclick and others only one. Double-click sensitivity (maximum time between clicks that is detected as a double click) can vary by operating system and browser, and is often user-configurable.

To bind a "Hello World!" alert box to the dblclick event on every paragraph on the page:

HTML
$("p").dblclick(function () {
  alert("Hello World!");
});
DEMO

Double click to toggle background color.

JS
<div></div>
<span>Double click the block</span>
CSS
div {
  background: blue;
  color: white;
  height: 100px;
  width: 150px;
}
div.dbl {
  background: yellow;
  color: black;
}
HTML
var divdbl = $("div").first();
divdbl.dblclick(function () {
  divdbl.toggleClass("dbl");
});
DEMO

Looking for a Web Developer?

👋

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)