9

I can disable it fine using this:

button.attr('disabled', 'disabled' ).addClass( 'ui-state-disabled' );

But how do I re-enable it? When I use this:

button.attr('enabled', 'enabled' ).addClass( 'ui-state-enabled' );

It doesn't work.

slandau
  • 23,528
  • 42
  • 122
  • 184

5 Answers5

21
button.removeAttr('disabled').removeClass( 'ui-state-disabled' );
Josiah Ruddell
  • 29,697
  • 8
  • 65
  • 67
5

Tried all the answers here and nothing worked for me.

The issue is that I have html:

<input type="submit" value="Save" id="saveButton" disabled="disabled" />

Then I call globaly:

$("button, input:submit, input:button").button();

After that the button gets attribute aria-disabled=true.

Neither of following will enable the submit:

$("#saveButton").attr('disabled',false);
$("#saveButton").removeAttr('disabled');
$("#saveButton").prop('disabled',false);
$("#saveButton").attr('aria-disabled',false);
$("#saveButton").removeClass('ui-state-disabled' );

The only working solution in this case is:

$("#saveButton").button( "enable" );

jQuery UI Docs: Button Widget - enable()

To disable button again:

$("#saveButton").button( "disable" );

jQuery UI Docs: Button Widget - disable()

sumid
  • 1,871
  • 2
  • 25
  • 37
  • **Hint:** Disabling works similar, see this [linked answer.](http://stackoverflow.com/a/4279852/1016343) – Matt May 19 '14 at 14:37
  • This is the correct answer. This way you're essentially telling jQuery to enable the button and having it do all the work. If you want to do the work yourself, you have to remove the `disabled` attribute, the jQuery UI disabled classes, _and_ set up the hover classes. No need to do all that by hand. – Ashley Strout Nov 19 '15 at 03:25
0

With jquery you can use removeAttr and removeClass to get rid of your disabled attribute/class:

button.removeAttr('disabled').removeClass('ui-state-disabled');
wajiw
  • 12,239
  • 17
  • 54
  • 73
0

Just remove the disabled attribute.

http://api.jquery.com/removeAttr/

button.removeAttr("disabled")
timroman
  • 1,384
  • 1
  • 10
  • 18
0

I think that this is what are you looking for:

button.removeAttr("disabled");
João Louros
  • 2,752
  • 4
  • 23
  • 30