How to add disabled attribute to input element using JavaScript?

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.