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.).
To make the disabled button, we will use the Pure CSS class “pure-button-disabled” with the class “pure-button”. We can also create a disabled button using disabled attribute. Disabled Button used Class: pure-button-disabled: It is used to disable the Pure CSS button.
You just need the $('button').prop('disabled', true);
part, the button will automatically take the disabled class.
For input and button:
$('button').prop('disabled', true);
For anchor:
$('a').attr('disabled', true);
Checked in firefox, chrome.
See http://jsfiddle.net/czL54/2/
Building off jeroenk's answer, here's the rundown:
$('button').addClass('disabled'); // Disables visually
$('button').prop('disabled', true); // Disables visually + functionally
$('input[type=button]').addClass('disabled'); // Disables visually
$('input[type=button]').prop('disabled', true); // Disables visually + functionally
$('a').addClass('disabled'); // Disables visually
$('a').prop('disabled', true); // Does nothing
$('a').attr('disabled', 'disabled'); // Disables visually
See fiddle
The easiest way to do this, is to use the disabled
attribute, as you had done in your original question:
<button class="btn btn-disabled" disabled>Content of Button</button>
As of now, Twitter Bootstrap doesn't have a method to disable a button's functionality without using the disabled
attribute.
Nonetheless, this would be an excellent feature for them to implement into their javascript library.
<div class="bs-example">
<button class="btn btn-success btn-lg" type="button">Active</button>
<button class="btn btn-success disabled" type="button">Disabled</button>
</div>
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