k.ken k.ken - 1 year ago 152
Javascript Question

Disabling and enabling a html input button

So I have a button like this:

<input id="Button" type="button" value="+" style="background-color:grey" onclick="Me();"/>

How can I disable and enable it when I want? I have tried
but enabling it back is a problem. I tried setting it back to false but that didn't enable it.

Answer Source

All versions of jQuery prior to 1.6

Disabling a html button in jQuery


Enabling a html button



All versions of jQuery after 1.6

Disabling a html button in jQuery

$('#Button').prop('disabled', true);

Enabling a html button

$('#Button').prop('disabled', false);


P.S. Updated the code based on jquery 1.6.1 changes. As a suggestion, always use the latest jquery files and the prop() method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download