Categories
JavaScript Answers

How to add disabled attribute to input element using JavaScript?

Spread the love

Sometimes, we want to add disabled attribute to input element using JavaScript.

In this article, we’ll look at how to add disabled attribute to input element using JavaScript.

How to add disabled attribute to input element using JavaScript?

To add disabled attribute to input element using JavaScript, we can set the disabled property of the select element to true.

For instance, we write

<select id="selectFrom">
  ...
</select>

to add the select element.

then we write

document.getElementById("selectFrom").disabled = true;

to get the select element with getElementById.

Then we set its disabled property to true to make it disabled.

Conclusion

To add disabled attribute to input element using JavaScript, we can set the disabled property of the select element 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 *