I want to clear the selection of checkboxes if they click cancel. How can I achive this with this code:
var chkbox= $('#divListBox').find(':checked') .map(function() { return $(this).val(); }).get();
If you want to delete the checkbox, you need to press and hold CTRL, click on the checkbox, and press DELETE on the keyboard.
Once the checkbox is selected, we are calling prop() function as prop( "checked", true ) to check the checkbox and prop( "checked", false ) to uncheck the checkbox.
Clicking on the master checkbox selects all checkboxes; and unchecking it, deselects all checkboxes.
This should work:
$('#divListBox :checked').removeAttr('checked');
The advantage of this solution is if you have on change events or on click events tied to the checkbox this will make them happen.
$('#divListBox').each(function(index, element) { var checked = element.checked; if (checked) { $(element).trigger('click'); } });
Also with bootstrap the checkbox wasn't getting found with the :checked
selector.
Hope that helps.
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