How to disable all input buttons with JavaScript?

Sometimes, we want to disable all input buttons with JavaScript.

In this article, we’ll look at how to disable all input buttons with JavaScript.

How to disable all input buttons with JavaScript?

To disable all input buttons with JavaScript, we can select all the input elements and loop through them to set the disabled property of each to true.

For instance, we write:

<input type='button' value='button'>
<input type='button' value='button'>
<input type='button' value='button'>

to add a few input elements.

Then we write:

const inputs = document.getElementsByTagName("input");
for (const input of inputs) {
  input.disabled = true
}

to select all the inputs with getElementsByTagname.

Next, we loop through each input with the for-of loop.

In the loop body, we set the disabled property of each input to true to disable them.

Conclusion

To disable all input buttons with JavaScript, we can select all the input elements and loop through them to set the disabled property of each to true.