Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get unchecked checkboxes using just javascript

Tags:

javascript

I can get all checked checkboxes with:

document.querySelectorAll('input[type=checkbox]:checked')

Is there a way to get the unchecked boxes?

like image 765
DCR Avatar asked Dec 30 '25 03:12

DCR


1 Answers

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>
like image 198
CertainPerformance Avatar answered Jan 01 '26 20:01

CertainPerformance



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!