DEV Community

Mahmoud Elmahdi
Mahmoud Elmahdi

Posted on

5 1

Are they all checked?

Simplest way to check whether all checkbox input fields checked or not; by converting a NodeList to an Array using ES6 ... spread operator so we can attach every() method to it;

Checkout the Are they all checked? Demo on jsfiddle

[...document.querySelectorAll('input')].every(checkbox => checkbox.checked)
Enter fullscreen mode Exit fullscreen mode

Top comments (5)

Collapse
 
mahmoudelmahdi profile image
Mahmoud Elmahdi

Thanks Arden! You can definitely do the same thing with Array.from, but in my case, the ... is better use IMO. Less code, easy to remember, plus performance. Cheers

Collapse
 
joelnet profile image
JavaScript Joel

Also

Array.prototype.every.call(document.querySelectorAll('input'), checkbox => checkbox.checked)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay