D3: How do I set “click” event and “dbclick” event at the same time?

You have to do your “own” doubleclick detection

Something like that could work:

var clickedOnce = false;
var timer;

$("#test").bind("click", function(){
    if (clickedOnce) {
        run_on_double_click();
    } else {
        timer = setTimeout(function() {
           run_on_simple_click(parameter);
        }, 150);
        clickedOnce = true;
    }
});

function run_on_simple_click(parameter) {
    alert(parameter);
    alert("simpleclick");
    clickedOnce = false;
}

function run_on_double_click() {
    clickedOnce = false;
    clearTimeout(timer);
    alert("doubleclick");
}

Here is a working JSFiddle

For more information about what delay you should use for your timer, have a look here : How to use both onclick and ondblclick on an element?

Leave a Comment