How to disable the HTML button in JavaScript
Learn, how to disable or enable the button in JavaScript.
We mostly disabled the button when a text input element is empty or a checkbox is not checked in the signup forms.
Disabling the button
To disable the button, first we need to access the button
element inside JavaScript using document.querySelector()
method.
const btn = document.querySelector('.submit');
Now, we need to set its disabled
property to true
.
btn.disabled = true;
We can enable it back by setting the disabled
property to false
.
btn.disabled = false;