In jQuery, the standard way to disable or enable a submit button is using .prop("disabled", true) and .prop("disabled", false). Updating the .prop("disabled", ...) property modifies the live DOM element state reliably and works cleanly with form submission and CSS state styling.


1. Disabling and Enabling with .prop("disabled", ...)

Use .prop() rather than .attr() when toggling boolean element states like disabled:

// Disable and re-enable a submit button using jQuery .prop()
function setSubmitButtonDisabled(selector, isDisabled) {
  $(selector).prop("disabled", Boolean(isDisabled));
}

// Example usage on a submit button
$("#submit-btn").prop("disabled", true);  // Disables the button
$("#submit-btn").prop("disabled", false); // Re-enables the button

// Toggle based on an input value (e.g., non-empty email)
$("#email-input").on("input", function () {
  const hasText = $(this).val().trim().length > 0;
  $("#submit-btn").prop("disabled", !hasText);
});
  • .prop("disabled", true): Sets the DOM disabled property so clicks and form submissions are blocked.
  • .prop("disabled", false): Removes the disabled state and restores normal button interactivity.
  • Boolean argument: Passing true or false directly makes state toggling clear and predictable.

2. Disabling During Form Submission or Async Requests

A common pattern is disabling the submit button as soon as a form submits, then re-enabling it if validation fails or an async request completes:

// Prevent double form submission while handling async work
$("#signup-form").on("submit", async function (event) {
  event.preventDefault();
  const $submitBtn = $(this).find('button[type="submit"], input[type="submit"]');

  $submitBtn.prop("disabled", true).text("Submitting...");

  try {
    await Promise.resolve(); // Replace with your actual request/validation logic
  } finally {
    $submitBtn.prop("disabled", false).text("Submit");
  }
});
  • Scope to the form ($(this).find(...)): Targets the submit button inside the specific form being submitted rather than every button on the page.
  • Restore state in finally: Ensures the button gets re-enabled even if an error occurs during submission.

3. Common Traps to Avoid

Toggling button state in jQuery runs into a few frequent pitfalls:

  • Using .attr("disabled", ...) instead of .prop("disabled", ...): .prop() directly updates the live DOM boolean property, which is more reliable across repeated toggles.
  • Checking .attr("disabled") to read current state: Read $("#submit-btn").prop("disabled") to get a true boolean (true or false).
  • Forgetting event.preventDefault() on invalid forms: If you block submission manually, prevent the default submit action so the page does not reload unexpectedly.

TL;DR: Use $("#submit-btn").prop("disabled", true) to disable and $("#submit-btn").prop("disabled", false) to re-enable a submit button in jQuery.

Are you toggling the button based on form validation rules, during an AJAX/async submit request, or with a checkbox agreement?