Categories
JavaScript Answers

How to get all checked checkboxes with JavaScript?

Spread the love

Sometimes, we want to get all checked checkboxes with JavaScript.

In this article, we’ll look at how to get all checked checkboxes with JavaScript.

How to get all checked checkboxes with JavaScript?

To get all checked checkboxes with JavaScript, we use querySelectorAll.

For instance, we write

const checkedBoxes = document.querySelectorAll(
  "input[name=mycheckboxes]:checked"
);

to call querySelectorAll with "input[name=mycheckboxes]:checked" to select all checkboxes with the name attribute set to mycheckboxes.

And we use :checked to select the checked ones with the attribute.

Conclusion

To get all checked checkboxes with JavaScript, we use querySelectorAll.

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 *