Skip to content Skip to sidebar Skip to footer

Triggering Double Click Via Jquery Or Pure Javascript For A Single Click Event

I want to trigger double click event on any element when a single click event occurs in that element. To be more clear, let's say I have a text box with some text, and when the us

Solution 1:

The code you provided above works for me. A double click is triggered when a single click occurs. I used this variation:

var numd = 0; 
$("#content").dblclick(function() { 
    numd++; 
});
$("#content").click(function() { 
    $(this).dblclick(); 
});

numd is incremented correctly.

For multiple clicks:

You could use a variable to keep track of which click you are on while using the click() method to perform clicks. Here is an example to trigger a triple click.

var clicknum = 0;
$("#text-box").click(function() {
    clicknum++;
    if (clicknum < 3) {
        $(this).click();
    }
    else {
        // Reset clicknum since we're done.
        clicknum = 0;
    }
}

Post a Comment for "Triggering Double Click Via Jquery Or Pure Javascript For A Single Click Event"