Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all unselected checkboxes?

In jQuery, how does one go about finding all the 'unchecked' checked boxes.

$(':checkbox:checked');

appears to be me all checked boxes, but what I need is all non-checked boxes.

like image 709
Jim Biddison Avatar asked Jul 07 '09 16:07

Jim Biddison


People also ask

How do I unselect all checkboxes?

Clicking on the master checkbox selects all checkboxes; and unchecking it, deselects all checkboxes. Create a new file 'CheckAllCheckboxes. html'. Set up five checkbox elements in a paragraph with an ID of checkBoxes.

How do you check if no checkbox is selected?

prop() and is() method are the two way by which we can check whether a checkbox is checked in jQuery or not. prop(): This method provides an simple way to track down the status of checkboxes. It works well in every condition because every checkbox has checked property which specifies its checked or unchecked status.

How do I uncheck all checkboxes in react?

To uncheck a checkbox programmatically in React, we can set the checked prop of the checkbox to a state. We have the checked state that we used to set the checked prop of the checkbox. Then we add a button that calls setChecked to toggle the checked value when we click the button.


1 Answers

You use the :not selector, like so:

$('input:checkbox:not(:checked)');

Or the .not function, like so:

$('input:checkbox').not(':checked');

Also note that you should always put input before filters like :radio and :checkbox, as without that the selector are evaluated as *:checkbox which is a really slow selector.

like image 107
Paolo Bergantino Avatar answered Sep 30 '22 10:09

Paolo Bergantino