Disable the button element in JavaScript
Learn, how to disable or enable the button in JavaScript.
Normally, We disabled the button when a input text element is empty or a checkbox is not checked in the signup or login 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;