xxxxxxxxxx
//using plane javascript
if(document.getElementById('on_or_off_checkbox').checked) {
//I am checked
}
//using jQuery
if($('#on_or_off_checkbox').is(':checked')){
//I am checked
}
xxxxxxxxxx
$( "SELECTOR" ).attr( "checked" ) // Returns ‘true’ if present on the element, returns undefined if not present
$( "SELECTOR" ).prop( "checked" ) // Returns true if checked, false if unchecked.
$( "SELECTOR" ).is( ":checked" ) // Returns true if checked, false if unchecked.
xxxxxxxxxx
if ($('#grepperRocks').is(':checked')) {
// this checkbox is checked
}
xxxxxxxxxx
//using plane javascript
if(document.getElementById('on_or_off_checkbox').checked) {
//I am checked
}
//using jQuery
if($('#on_or_off_checkbox').is(':checked')){
//I am checked
}
xxxxxxxxxx
var isChecked = $('#checkboxId').prop('checked');
if(isChecked == true){
//code
}
xxxxxxxxxx
// HTML
<input type="checkbox" id="myCheckbox">
// jQuery
if ($('#myCheckbox').is(':checked')) {
console.log('Checkbox is checked');
} else {
console.log('Checkbox is not checked');
}