I can get all checked checkboxes with:
document.querySelectorAll('input[type=checkbox]:checked')
Is there a way to get the unchecked boxes?
You can use the not psuedo-selector in combination with checked:
console.log(
document.querySelectorAll('input[type=checkbox]:not(:checked)').length
);
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox" checked>
<input type="checkbox" checked>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With