How to Disable a Button with jQuery

Ever needed to stop someone from clicking a button too early, like before filling out a form or while something’s loading? That’s where disabling buttons comes in handy.
With jQuery, this is super straightforward. Let’s walk through how it works, with clear examples you can copy and tweak for your site.
First Things First: What Does “Disable” Mean?
When we say we’re “disabling” a button, we mean we’re preventing users from being able to click it. It also usually looks a bit faded or greyed out, giving people a visual cue that it’s not ready to use.
In HTML, you can disable a button by adding the disabled
attribute:
htmlCopyEdit<button disabled>Click Me</button>
But if you want to do this dynamically, like based on user action, that’s where jQuery steps in.
jQuery Setup (Just in Case)
Before anything else, make sure jQuery is loaded on your page. You can add it like this:
htmlCopyEdit<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
Once that’s in place, you’re good to go.
How to Disable a Button Using jQuery
Let’s say you have a button like this:
htmlCopyEdit<button id="myButton">Submit</button>
To disable it using jQuery, you’d do this:
javascriptCopyEdit$('#myButton').prop('disabled', true);
Just like that, the button is now disabled.
And to enable it again?
javascriptCopyEdit$('#myButton').prop('disabled', false);
Simple toggle. No headaches.
Real-Life Example: Disable on Form Submit
Here’s a common use case: You’ve got a form, and you want to disable the submit button right after someone clicks it, so they don’t accidentally submit twice.
htmlCopyEdit<form id="myForm">
<input type="text" placeholder="Your name" required>
<button type="submit" id="submitBtn">Send</button>
</form>
javascriptCopyEdit$('#myForm').on('submit', function(e) {
$('#submitBtn').prop('disabled', true);
});
That’s it. One click, and the button locks itself.
Another Trick: Disable Based on Input
Want the button to stay disabled until someone fills out a field?
htmlCopyEdit<input type="text" id="nameField" placeholder="Your name">
<button id="submitBtn" disabled>Send</button>
javascriptCopyEdit$('#nameField').on('keyup', function() {
let value = $(this).val().trim();
$('#submitBtn').prop('disabled', value === '');
});
This keeps the button disabled until the user types something. Super useful for login forms, email signups, and similar stuff.
Quick Recap
Here’s the gist:
- Use
.prop('disabled', true)
to disable - Use
.prop('disabled', false)
to enable - jQuery makes it quick and clean
- Great for improving UX and avoiding double-click chaos
Final Thoughts
Whether you’re working on a basic contact form or a more complex checkout flow, knowing how to control buttons with jQuery is a handy trick to have in your toolbelt.
Featured image by storyset on Freepik