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
.