I want to uncheck all checkboxex inside the 'test' div without those checkboxes whose attributes are disabled.
<div id="test">
<input type="checkbox" id="check1" name="check1">
<input type="checkbox" id="check01" name="check01" disabled="disabled">
<input type="checkbox" id="check2" name="check2" disabled="disabled">
<input type="checkbox" id="check3" name="check3">
<input type="checkbox" id="check4" name="check4">
<input type="checkbox" id="check50" name="check50">
<input type="checkbox" id="check6" name="check6">
</div>
<input type="button" id="uncheckAll" onclick="uncheckAll('test')">
<script language="javascript">
function uncheckAll() {
$('#' + divid + ' :checkbox').attr('checked', false);
/*
This function uncheck all of the checkboxes, which i don't want, i want to
uncheck only checkboxes whose attributes are not disabled.
/*
}*/
</script>
You need to accept the param named divId then use :enabled filter to filter out disabled checkboxes
function uncheckAll(divid) {
$('#' + divid + ' :checkbox:enabled').prop('checked', false);
}
Demo: Fiddle
If no jQuery
function uncheckAll(divid) {
var checks = document.querySelectorAll('#' + divid + ' input[type="checkbox"]');
for(var i =0; i< checks.length;i++){
var check = checks[i];
if(!check.disabled){
check.checked = false;
}
}
}
Demo: Fiddle