//using plane javascript if(document.getElementById('on_or_off_checkbox').checked){//I am checked}//using jQueryif($('#on_or_off_checkbox').is(':checked')){//I am checked}
$("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.
// Check a checkbox$(selector).prop('checked',true);// Un-check a checkbox$(selector).prop('checked',false);// Determine if checked or not
isChecked =$(selector).prop('checked');
$('input[type="checkbox"]').click(function(){if($(this).is(":checked")){console.log("Checkbox is checked.");}elseif($(this).is(":not(:checked)")){console.log("Checkbox is unchecked.");}});
How to check whether a checkbox is checked in jQuery?
//using plane javascript if(document.getElementById('on_or_off_checkbox').checked){//I am checked}//using jQueryif($('#on_or_off_checkbox').is(':checked')){//I am checked}
<script>$(document).ready(function(){$('input[type="checkbox"]').click(function(){if($(this).prop("checked")==true){console.log("Checkbox is checked.");}elseif($(this).prop("checked")==false){console.log("Checkbox is unchecked.");}});});