Categories
JavaScript Answers

How to disable an input field using JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *