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.
Checking if the button is disabled or enabled with jQuery removeAttr('disabled'); }; const checkButton = (e) => { const isDisabled = $('#my-button'). prop('disabled'); if( isDisabled ){ alert("Is disabled!"); } else{ alert("Is enabled"); } }; $(document).
Using jQuery With jQuery, you can use the . attr() method to add disabled HTML attribute to the submit button and . removeAttr() method to remove the disabled attribute from it. The value of the disabled HTML attribute indicates whether the element is enabled or disabled.
The disabled attribute is a boolean attribute. When present, it specifies that the button should be disabled. A disabled button is unusable and un-clickable. The disabled attribute can be set to keep a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc.).
button.removeAttr('disabled').removeClass( 'ui-state-disabled' );
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With