Categories
JavaScript Answers

How to reset all checkboxes using JavaScript?

Spread the love

Sometimes, we want to reset all checkboxes using JavaScript.

In this article, we’ll look at how to reset all checkboxes using JavaScript.

How to reset all checkboxes using JavaScript?

To reset all checkboxes using JavaScript, we can set the checked property of each checkbox to false.

For instance, we write

const clist = document.getElementsByTagName("input");
for (const el of elist) {
  el.checked = false;
}

to select all inputs with getElementsByTagName.

Then we loop through them with a for-of loop and set each checkbox input’s checked property to false to uncheck all the checkboxes.

Conclusion

To reset all checkboxes using JavaScript, we can set the checked property of each checkbox to false.

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 *