.dblclick()S2C Home « Events « .dblclick()

Mouse double click event handler.

Description

The .dblclick() method is used to bind an event handler to the JavaScript dblclick event or trigger that event on the specified element.

  • The dblclick event is sent to an element when:
    1. The mouse pointer is inside the element and the primary mouse button is pressed down.
    2. The primary mouse button is then released while the mouse pointer is inside the element.
    3. The mouse pointer is inside the element and the primary mouse button is pressed down again within a time window that can be system dependant and user configurable.
    4. The primary mouse button is then released again while the mouse pointer is inside the element.
  • It is not best practice to bind event handlers to both the .click() and dblclick events for the same element:
    1. The sequence of events triggered can vary from browser to browser, with some browsers receiving two .click() events before the dblclick event while other browsers receive only one
    2. Double-click sensitivity, which is the maximum time between clicks that will be detected as a double click, can be system dependant and is generally user configurable.

Syntax


Signature Description
.dblclick( )Trigger the dblclick JavaScript event on the specified element.
.dblclick([eventData], handler(eventObject))Bind an event handler to the dblclick JavaScript event, optionally passing an object of data.

Parameters


Parameter Description Type
eventDataAn object of data to pass to the event handler.Object
handler( eventObject )A function to execute each time the event is triggered.Function

Return

A jQuery object.

.dblclick( ) Examplego to top of page Top

Trigger the dblclick JavaScript event on the specified element.

  • This signature is a shortcut for .trigger('dblclick').

In the example below we toggle the pie image with the id of 'pie1' when the user double clicks anywhere in the div with an id of 'div17' or double clicks the button below.

When the user double clicks the button we trigger off the dblclick JavaScript event on the 'div14' element. This then fires off the $('#div14').dblclick(function(){}) code which shows the image.

Alternatively if you just dblclick in the division the dblclick event handler runs without being triggered to toggle the image.

a picture of pie



$(function(){
  $('#btn2').dblclick(function () {
    $('#div17').dblclick();
  });
  $('#div17').dblclick(function () {
    $('#pie2').toggle();
  });
});

Press the buttons below to action the above code:

.dblclick( [eventData], handler(eventObject) ) Examplego to top of page Top


  • This signature is a shortcut for .bind('dblclick', handler).

Bind an event handler to the dblclick JavaScript event, optionally passing an object of data.

In the example below we show a new message in the 'p' element with an id of 'scrollspan9' each time the 'div' element with an id of 'div18' below is hovered over and the primary mouse button is double clicked inside this element.

When the primary mouse button is double clicked inside this element, the dblclick JavaScript event fires off the $('#div18').dblclick({ param1: '#scrollspan9', param2: 'dblclick ', param3: '**JavaScript event triggered** ' }, addText2); code.

What we are doing here is passing across the event object to the function addText2(event). The map we specify, in our case { param1: '#scrollspan9', param2: 'dblclick ', param3: '**JavaScript event triggered** ' } gets tagged onto the event.data property. We then access this parameter in the function via event.data.param and use it as part of the appended data.


$(function(){
  $('#div18').dblclick({ param1: '#scrollspan9', param2: 'dblclick ', 
                         param3: '**JavaScript event triggered**  ' }, addText2);
  function addText2(event) {
    $(event.data.param1).append(event.data.param2 + ''<code>' + event.data.param3+ ''</code>');
  }
});

div18. double click Here.

We will show a message here.

go to home page Homepage go to top of page Top