I am using jQuery to handle selecting all checkboxes for a form. Here's my code:
$(function () {
$('#selectall').on('click', function() {
$('.selectedId').attr('checked', $(this).is(":checked"));
});
});
<input type="checkbox" id="selectall">Select all</input>
<input type="checkbox" name="industry1" id="industry1" value="1" class="selectedId">
<input type="checkbox" name="industry2" id="industry2" value="1" class="selectedId">
When I check the selectall id checkbox
, it selects all of the checkboxes with the class selectedId
. When I click it again, it removes the checks against all.
My problem is though, after that initial select all/deselect all it no longer operates, as in I cannot select all.
Any idea what I should be doing in my javascript that will fix this issue?
Thanks!