Sometimes, we want to disable an input field using JavaScript.
In this article, we’ll look at how to disable an input field using JavaScript.
How to disable an input field using JavaScript?
To disable an input field using JavaScript, we can set the disabled
property of the input to true
.
For instance, we write:
<input>
to add an input.
Then we write:
const input = document.querySelector('input')
input.disabled = true
to select an input with querySelector
.
And then we set input.disabled
to true
to disable the input.
Conclusion
To disable an input field using JavaScript, we can set the disabled
property of the input to true
.