Reputation: 15197
I have a group of checkbox's and one of them is marked as all. If this is clicked i would like to check all the other checkbox's within this class, and if it is then clicked again i want to remove the check form all the checkbox's within that class.
At the moment when i check all, all my checkbox's are checked, then when i click all again, all the checkbox's become unchecked. If i try click all again only the all check box is clicked.
When the all check box is checked i run:
$('.chIndustry').attr('checked', 'checked');
When the all checkbox becomes unchecked:
$('.chIndustry').removeAttr('checked');
Upvotes: 0
Views: 83
Reputation: 2130
$(document).ready(function() {
$(".checkall").change(function() {
console.log($(this).is(':checked'))
if ($(this).is(':checked')) {
$('input[name="test"]').prop('checked', true);
} else {
$('input[name="test"]').prop('checked',false );
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<input type="checkbox" name="test" class="test" />
<input type="checkbox" name="test" class="test" />
<input type="checkbox" name="test" class="test" />
<input type="checkbox" name="test" class="test" />
<input type="checkbox" name="test" class="test" /></br/>
Check all <input type="checkbox" class="checkall" />
Upvotes: 1
Reputation: 1489
Try .prop
to uncheck the check the check box
$('.chIndustry').prop('checked', false);
Upvotes: 1