eThan_hunT eThan_hunT - 1 year ago 88
jQuery Question

How to check that all the checkboxes of a particular class are disabled using jquery?

I have a column in the table consists of checkboxes, I need to check whether all the checkboxes are disabled.

Here is my code

var checkBoxTdSize = $('.hrchy-dt-checkboxes').length;
var checkedFlag=false;
for(var t=0;t<checkBoxTdSize;t++){
var chk = $(this).find('.hrchy-dt-checkboxes')[t];
if ($(chk).prop('disabled')==true){
checkedFlag=true;
}else{
alert('Please Map all the Hierarchy..!');
}
}
if(checkedFlag){
//Some Code
}


But from the above code I always get alert "Please Map all the Hierarchy..!".

Help is appreciated, Thanks

Answer Source

If your checkboxes are not in any parent then why you are using find() method...?

$(document).ready(function() {
    var chk = $('.hrchy-dt-checkboxes');
    chk.each(function(index, el) {
        if ($(this).prop('disabled') == true) {
            //your code here
        }
    });
});

$(document).ready(function() {
    var chk = $('.hrchy-dt-checkboxes');
    chk.each(function(index, el) {
        if ($(this).prop('disabled') == true) {
        	var condi = true;
        	console.log('Disabled = ' + condi)
        }
        else {
        	console.log('Enabled..!')
        }
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" name="" class="hrchy-dt-checkboxes">
<input type="checkbox" name="" class="hrchy-dt-checkboxes">
<input type="checkbox" name="" class="hrchy-dt-checkboxes">
<input type="checkbox" name="" class="hrchy-dt-checkboxes">
<input type="checkbox" name="" class="hrchy-dt-checkboxes" disabled="disabled">

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download