I thought this was supposed to be easy. There are a lot of answers on here about unchecking checkboxes using jQuery but when I try them they don't seem to work. I want to uncheck them as part of my function for resetting the form.
I have a loop and I create checkboxes inside it:
<input type="checkbox" name="is_chosen[]" value="{{ $sample->id }}" class="flat">
Here is the my code for unchecking checkboxes (not all checkboxes are checked initially):
$('input:checkbox').each(function () {
if(this.checked) {
$(this).attr('checked', false);
}
});
I have also tried replacing attr
with prop
. I have also tried using just $(input:checkbox).prop('checked', false);
. I have tried others more but they don't work. What am I missing?