How to disable the button in Bootstrap using JavaScript
Learn, how to disable or enable the button in bootstrap using the JavaScript.
We mostly disabled the button when a input text element is empty or a checkbox is not checked in the signup forms.
Consider, we have a following bootstrap button:
<button type="button" class="btn btn-primary">Primary</button>
Now, we need to disable the above button.
Disabling the button in BootStrap using JavaScript
To disable the button, first we need to access the button
html element inside the JavaScript using document.querySelector()
method, then we need to set its disabled
property to true
. .
<button type="button" class="btn btn-primary">Primary</button>
const btn = document.querySelector('.btn-primary');
btn.disabled = true;
We can enable it back by setting the disabled
property to false
.
btn.disabled = false;
Similarly, we can also disable the button in bootstrap by adding a .disabled
class to it.
Example:
<button type="button" class="btn btn-primary disabled">
Primary
</button>