Browse - Programming Tips - How do I disable/enable a button with jQuery?

Date: 2010jun30
Updated: 2018jun21
Language: javaScript
Platform: web
Library: jQuery

Q.  How do I disable/enable a button with jQuery?

A.  Disable like this:

$('#mybutton').prop('disabled', true);
Enable like this:
$('#mybutton').prop('disabled', false);
You could make a wrapper function as so:
function enableButton(query, is_enabled) { $(query).prop('disabled', !is_enabled); }
Example use:
enableButton('#mybutton', false); // disables it enableButton('#mybutton', true); // enables it