When I dblclick, it runs .click twice

jquery click and double click on same element
javascript double click and single click
javascript trigger double click
ondblclick
jquery double click to edit text

I have 2 functions when you click on an item, .click and .dblclick The problem is, that when you dblclick, it runs the .click function twice. Is there a way to fix this?

$(".item").click(function() {
    if (price[this.id] === 1) {
        consoleUpdate("This item is worth " +price[this.id]+ " coin");
    }
}

$("#fishItem").unbind("dblclick").bind("dblclick").dblclick(function() {
    coins = coins+1;
    coinUpdate();
    invFish1--;
    if (invFish1 === 0) {
        $("#fishItem").appendTo("#itemStage");
    }
});   

Per the jQuery documentation for the dblclick event:

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.

You want to change your events so that you don't have a .click and .dblclick on the same element.

http://api.jquery.com/dblclick/

Double click inside cell triggers cell click twice. · Issue #2091 , I checked in Chrome, this causes my logics to run twice. And I don't have any cellDblClick configured for the cell. Any idea on how this can be  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. You want to change your events so that you don't have a .click and .dblclick on the same element.

var cnt=1;
$( "#target" ).click(function(e) {

if(cnt==1)
{

// action on single click if you dont want anything in in single click then use here
e.preventDefault();

}else{

// work on double click
cnt=1;// again set counter 
}

cnt++;
});

reference e.preventDefault();

Double click on the map emits 'click' event twice · Issue #6524 , mapbox-gl-js version: 0.44.2 Steps to Trigger Behavior Add event listeners: map.​on('dblclick', e => { console.log(e) }) map.on('click', e => { console.log(e) }  Hi, somethings has been changed in my win10 64b pro (Microsoft Windows [Version 10.0.17763.134]) box, and now I have issues with bat files: When I double click on them, I get a cmd, empty that shows up for a couple of seconds, and then closes.

As others mentioned, you can't really bind both click and double click to the same item. There are, however, workarounds.

One way to handle this would be to handle the click code and then check for double-click:

var lastClickTime = 0;
$(".item").click(function() {
    var thisClickTime = (new Date).getTime();

    if (thisClickTime - lastClickTime < 500) {
        //Double-click
    }
    else {
        //Click
    }
    lastClickTime = thisClickTime;
});

This code essentially captures a "last click time" and if this click time is less than 500 milliseconds from the last click time, then it fires the double-click code. Otherwise it will fire the click code.

The downside with this is that the click-code will be called first and then the double-click code. Also, you're forcing your users into a 500ms double-click. While this is pretty standard, it's not guaranteed. (Slower clickers may have trouble with this.)

A JSFiddle that demonstrates this technique.


You could improve this code by setting a 500ms timeout for the click code and then cancelling the click event if a double-click is fired. The downside with this is that it will force a 500 ms delay between the click and the "click" code.

A JSFiddle that demonstrates the timeout.

Element: dblclick event, The dblclick event fires when a pointing device button (such as a mouse's primary button) is double-clicked; that is, when it's rapidly clicked  By running a macro or an event procedure when the DblClick event occurs, you can open a window or document when an icon is double-clicked. Double-clicking a control causes both Click and DblClick events to occur. If the control doesn't already have the focus when you double-click it, the Enter and GotFocus events for the control occur before the Click and DblClick events. For objects that receive mouse events, the events occur in this order: MouseDown → MouseUp → Click → DblClick

If you don't mind handling one single-click, look at the event object details attribute. It is the number of clicks.

$(".item").click(function(event) {
    if (event.details === 1) {
        //handle single click
    } else if (event.details === 2) {
        // handle double click
    }
}

.dblclick(), The dblclick event is sent to an element when the element is double-clicked. After this code executes, (single) clicks on Trigger the handler will also alert the  Click on anything from an Icon and it opens Twice (2 Windows of Internet Explorer open or 2 WORD documents open etc.). Also, when you click on START or Favorites or File, the Pull Down Window flashes OPEN then in a Blink it is gone. So I have to click on the tab again and again until it OPENS and remains Open.

ListBox.DblClick event (Access), Double-clicking a control containing an OLE object starts the application used to create the object, allowing it to be edited. If the DblClick event  Double Click Doesn't Open PDF. Double Click Doesn't Open PDF Hi When I try to open a document by double clicking, or if try to open a document on a website by clicking it I get the message "Acrobat cannot open documents in the pdf format". This happens in Acrobat X Pro and in Acrobat Reader.

Report.DblClick event (Access), Double-clicking a control containing an OLE object starts the application used to create the object, allowing it to be edited. If the DblClick event 

How to Disable Double Click on Submit Button, A lot of web users double click links and form buttons. I've watched over the shoulder of friends, normally older friends who haven't grown up 

Comments