jQuery Disable Button After Click (4 Ways, With Examples)

Say you’re testing checkout for an online outdoor store, and a customer double-clicks Place Order on a $184.97 order. That’s two charges. The fix for jQuery disable button after click is one line in the click handler: $(this).prop("disabled", true).

In this tutorial, I’ll walk you through four fixes on the same checkout form: the click handler, the submit event, .one(), and an AJAX call that turns the button back on when the request fails.

The sample checkout form with a Place Order button

Every example uses one form: order A-20481 for Megan Carter in Denver, CO, totaling $184.97. People double-click while payment runs, so this Python backend waits 1.5 seconds on every POST and counts them.

For a real backend, see creating your first API with FastAPI.

# server.py - slow test backend for the checkout page
import json, sys, time
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer

PORT = int(sys.argv[1]) if len(sys.argv) > 1 else 8000
posts = []                               # every POST that reached us

class Checkout(SimpleHTTPRequestHandler):
    def do_POST(self):
        posts.append(self.rfile.read(int(self.headers["Content-Length"])))
        time.sleep(1.5)                  # a slow payment gateway
        status, ctype = 200, "text/html"
        body = ('<link rel="stylesheet" href="checkout.css"><h2>Order '
                f"received</h2><p>POST requests so far: {len(posts)}</p>")
        if self.path == "/api/orders":   # AJAX: the first call fails
            status, ctype = (200 if len(posts) > 1 else 503), "application/json"
            body = json.dumps({"order": "A-20481", "total": 184.97}
                              if status == 200 else {"error": "Payment gateway timeout"})
        self.send_response(status)
        self.send_header("Content-Type", ctype)
        self.end_headers()
        self.wfile.write(body.encode())

print(f"Test checkout server on http://127.0.0.1:{PORT}")
ThreadingHTTPServer(("127.0.0.1", PORT), Checkout).serve_forever()

I ran it with Python 3.12.5 and opened each page in Microsoft Edge 157 with jQuery 4.0.0, the current release. If $ is undefined for you, see the jQuery is not defined error.

checkout.html open in VS Code with the jQuery click handler, and python server.py running in the terminal
The checkout page in the editor and the Python test server running in the VS Code terminal.

Method 1: Disable the button on click with .prop() (Recommended)

Use this when the button runs JavaScript instead of submitting the form, so it’s type="button". Here’s the full checkout page:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Checkout</title>
  <link rel="stylesheet" href="checkout.css">
  <script src="https://code.jquery.com/jquery-4.0.0.min.js"></script>
</head>
<body>
  <form id="checkout" method="post" action="/orders">
    <h2>Order A-20481</h2>
    <p class="muted">Megan Carter, Denver, CO - arrives Nov 20, 2026</p>
    <p>Trail Runner Backpack: $129.99<br>
       2 x Insulated Water Bottle: $49.98<br>
       Shipping: $5.00</p>
    <p class="total">Total: $184.97</p>
    <input id="promo" name="promo" placeholder="Promo code">
    <button type="button" id="place-order">Place Order</button>
    <p id="status"></p>
  </form>
  <script>
    let clicks = 0;
    $("#place-order").on("click", function () {
      clicks += 1;
      $(this).prop("disabled", true).text("Processing...");
      $("#status").text("Placing order A-20481 for $184.97");
      console.log(`click handler ran ${clicks} time(s)`);
      console.log("disabled:", $(this).prop("disabled"));
    });
  </script>
</body>
</html>

Console output:

click handler ran 1 time(s)
disabled: true

I clicked twice; the handler ran once, because a disabled button fires no click event.

jQuery disable button after click: Place Order button enabled before the click and grey with Processing text after it
After the click, Place Order turns grey, reads Processing… and ignores clicks.

How does this code work?

this is the clicked button (more in getting the id of the clicked element). .prop("disabled", true) sets its live disabled property and returns the same object, so .text() chains after it.

Pro Tip: Add a button:disabled CSS rule. Custom button colors override the browser’s grey, so a disabled button can look enabled.

Method 2: Stop double form submission with the submit event

With a type="submit" button, you handle the form’s submit event; it also fires when you press Enter. Same checkout form, now posting to /orders:

$("#checkout").on("submit", function () {
  $("#place-order").prop("disabled", true).text("Placing order...");
  console.log("submit handler ran: Place Order disabled");
});

Console output:

submit handler ran: Place Order disabled

I double-clicked Place Order on both versions: 2 POST requests reached the server without a handler, and 1 with it.

Server response after a double click: 2 POST requests without a guard, 1 with the jQuery submit handler
2 POST requests without a guard, 1 with the submit handler.

How does this code work?

The submit event fires after the click, so disabling the button there only blocks the second click.

Important: Don’t disable a submit button in its click handler. When I tried that in Edge, the form never posted at all.

Validate the fields before you disable anything; validating a form before submit with jQuery shows how.

Method 3: Let the click handler run only once with .one()

.one() attaches a handler that jQuery removes after its first run. On the same checkout form, I clicked three times:

let clicks = 0, runs = 0;
$("#place-order").on("click", () => clicks++);       // counts every click
$("#place-order").one("click", function () {         // runs once
  runs++;
  $(this).text("Processing...");
});
$("#place-order").on("click", () => {
  $("#status").text(`Clicks: ${clicks}, order handler runs: ${runs}`);
  console.log(`clicks: ${clicks}, one() handler runs: ${runs}`);
});

Console output:

clicks: 1, one() handler runs: 1
clicks: 2, one() handler runs: 1
clicks: 3, one() handler runs: 1
jQuery one() click handler: three clicks on Place Order, order handler ran once
Three clicks, but the order handler attached with .one() ran only once.

How does this code work?

The .on() counter sees all 3 clicks, but the .one() handler unbinds itself after the first.

So here’s the catch: the button still looks clickable. Plain JavaScript’s version is addEventListener("click", fn, { once: true }); see JavaScript vs jQuery.

Method 4: Re-enable the button after an AJAX request

You disable the button, then handle the server’s answer. The same order goes to /api/orders, which fails the first time with a 503:

$("#place-order").on("click", function () {
  const $btn = $(this).prop("disabled", true).text("Placing order...");
  $("#status").removeClass("err").text("Contacting the payment gateway...");

  $.ajax({ url: "/api/orders", method: "POST", dataType: "json",
           data: { order: "A-20481", total: "184.97" } })
    .done(function (res) {
      $btn.text("Order placed");                     // stays disabled
      $("#status").text(`Order ${res.order} placed: $${res.total.toFixed(2)}`);
      console.log(`done: order ${res.order}, $${res.total.toFixed(2)}`);
    })
    .fail(function (xhr) {
      $btn.prop("disabled", false).text("Try Again"); // re-enable
      $("#status").addClass("err")
        .text(`${xhr.responseJSON.error} (${xhr.status}). Try again.`);
      console.log(`fail: ${xhr.status} ${xhr.responseJSON.error}`);
    });
});

Console output:

fail: 503 Payment gateway timeout
done: order A-20481, $184.97

The first try failed and the button came back as Try Again; the retry placed order A-20481 for $184.97.

Place Order disabled while the AJAX request runs, then re-enabled as Try Again after a 503 error
Disabled while the request runs; enabled again as Try Again after the 503.
jQuery AJAX success: order A-20481 placed for $184.97 and the button stays disabled
The retry succeeds, and the button stays disabled.

How does this code work?

.done() runs on success and leaves the button disabled. .fail() runs on errors like 503 and calls .prop("disabled", false) so you can retry.

For a Save or Search button, re-enable it in .always() instead. More on callbacks: waiting for a function to finish in jQuery.

Why use .prop() instead of .attr() to disable a button?

The browser checks the disabled property; the attribute is only the HTML’s starting value. Here are four calls in jQuery 3.7.1 and 4.0.0:

for (const jq of [jq3, jQuery]) {                // 3.7.1, then 4.0.0
  const $btn = jq("<button>Place Order</butt