Reputation: 6471
If I click on checkAll
I want to check all checkboxes except the disabled ones.
$("#checkAll").click(function () {
$(".projectlist input:checkbox").each(function () {
if($(this).is(':enabled')){
$('.projectlist input:checkbox').not(this).prop('checked', this.checked);
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="projectlist">
<input id="checkAll" type="checkbox"><br>
<input disabled type="checkbox"><br>
<input disabled type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
</div>
Upvotes: 1
Views: 215
Reputation: 15555
$("#checkAll").click(function() {
$('.projectlist input:checkbox:enabled').prop('checked', this.checked);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="projectlist">
<input id="checkAll" type="checkbox"><br>
<input disabled type="checkbox"><br>
<input disabled type="checkbox"><br>
<input type="checkbox"><br>
<input type="checkbox"><br>
</div>
Description: Selects all elements that are enabled.
Upvotes: 4