How to check if a checkbox is checked with jQuery
In this tutorial, we are going to see how to check if a checkbox is checked with jQuery. You can easily use the selector :checked of jQuery with the method prop() to check if the checkbox is checked. Here is an example:
How to check if a checkbox is checked with jQueryUsing prop() method
JQuery’s prop() method provides an easy and reliable way to track checkbox status. It works well in all conditions because each checkbox has a property that specifies its status checked or not.
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
if($(this).prop("checked") == true){
alert("Checkbox is checked.");
}
else if($(this).prop("checked") == false){
alert("Checkbox is not checked.");
}
});
});
How to check if a checkbox is checked with jQuery Using :checked Selector
You can also use the “:checked” selector to check the state of checkbox. The “:checked” selector specifically designed for the radio button and checkboxes.
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
if($(this).is(":checked")){
alert("Checkbox is checked.");
}
else if($(this).is(":not(:checked)")){
alert("Checkbox is not checked.");
}
});
});




