javascript select all CHECKBOX that not hidden

Viewed 41

I have several checkboxes in the page. Some have hidden=true and the others hidden=false.

I already tried using a selector or jQuery to find checkbox that have the hidden property.

What I want to achieve is I've got number of

  1. hidden checkbox
  2. not hidden checkbox
  3. checked not hidden checkbox
let checkedBoxes = document.querySelectorAll('input[hidden=false]');
let checkBoxes = document.querySelectorAll('input[hidden=false]:checked');

console.log(checkBoxes.length);
console.log(checkedBoxes.length);
1 Answers

try the negation operator

    
let checkBoxes = document.querySelectorAll('input:not([hidden])');
console.log(checkBoxes)
<input hidden /><input  /><input  /><input hidden /> 

if you are using JQuery there is also the :visible selector

Related