How to disable double-click on an element using Jquery?

While searching the internet for the solution to this problem, there were many solutions with different approaches. I tried many of them, but the best one to fulfill my need is below.

Jquery Function

jQuery.fn.trackClicks = function () {
    if ($(this).attr("data-clicks") === undefined) $(this).attr("data-clicks", 0);

    var timer;
    $(this).click(function () {
        $(this).attr("data-clicks", parseInt($(this).attr("data-clicks")) + 1);

        if (timer) clearTimeout(timer);

        var item = $(this);
        timer = setTimeout(function() {
            item.attr("data-clicks", 0);
        }, 300);


$(function () {

    $("a").click(function () {
        if ($(this).attr("data-clicks") === "2") {
            // Double clicked

I found this solution on this link.

Here, I have changed the timer to 300 which was best suited for me.

Hope this helps you as well.

92 thoughts on “How to disable double-click on an element using Jquery?”

Leave a Comment

Your email address will not be published. Required fields are marked *