How can I determine if a checkbox is checked or not? I have tried using various methods but have not been able to successfully determine the checked state of the checkbox.
There are many options to check whether a check box is checked. Here are a few examples below.
jQuery is() method
if( $(this).is(':checked') ){
// do something
}
jQuery prop() method
if( $(this).prop('checked') == true ){
// do something
}
jQuery check length
if ( $('input[type="checkbox"]:checked').length ) {
// do something
}
Pure JavaScript
if( document.getElementById('checkboxid').checked ) {
// do something
}
You can use any of the solutions above.