How to Disable/Enable the Button using 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;
Full working exmaple:
const btn = document.querySelector('.submit');
btn.disabled = true;
To enable the button back, we need to set it’s disabled
property to a value false
.
btn.disabled = false;