Disabling links to stop double-clicks in JQuery

This is what I would try:

$("a.button").one("click", function() {
    $(this).click(function () { return false; });
});

Bind all the links with class “button”. Run the anonymous function only once (hence “one”), which rebinds the link to return false.

If you want to keep it looking more like what you have, try this:

$("a.button").click(function() { $(this).attr("disabled", "disabled"); });
$(document).click(function(evt) {
     if ($(evt.target).is("a[disabled]"))
          return false;
});

Leave a Comment