When dealing with jQuery selectors, scenarios arise where you need to select a set of elements while excluding others. In this case, selecting all checkboxes present on a web page, but not a particular one, can be achieved with a few lines of jQuery code.
Given a markup consisting of a table with several input checkboxes, with one checkbox having a unique ID of "select_all," the objective is to select all checkboxes except the "#select_all" checkbox when it is clicked.
jQuery Code:
To accomplish this, you can utilize the following jQuery code:
$('#select_all').change(function() { var checkboxes = $(this).closest('form').find(':checkbox'); checkboxes.prop('checked', $(this).is(':checked')); });
Explanation:
This approach effectively toggles the checked state of all checkboxes when the "select_all" checkbox is clicked.
The above is the detailed content of How to Select All Checkboxes Except for a Specific One with jQuery?. For more information, please follow other related articles on the PHP Chinese website!