JQuery Check If Checkbox is Checked or Not Example

April 25, 2020 | Category : JQuery

Hi Dev,

This tutorial is focused on jquery get checkbox value if checked. i would like to show you how to check checkbox is checked or not in jquery using id. This article goes in detailed on jquery check if checkbox is checked or not. We will use how to check checkbox is checked or not in jquery on button click.

if you have question about how to check checkbox is checked or not in jquery using id then i will give simple example with solution. You just need to some step to done jquery check if checkbox is checked or not.

We will use jquery prop() method to check checkbox is checked or not. So you can see bellow simple full example that will help you to understand example.

Solution:

$('input[type="checkbox"]').click(function(){

if($(this).prop("checked") == true){

alert("you checked checkbox.");

}else if($(this).prop("checked") == false){

alert("you unchecked checkbox.");

}

});

Example:

<!DOCTYPE html>

<html>

<head>

<title>jquery check if checkbox is checked or not - itsolutionstuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

</head>

<body>

<h1>jquery check if checkbox is checked or not - itsolutionstuff.com</h1>

<label>

<input type="checkbox" name="i_agree"> I agree

</label>

<script>

$(document).ready(function(){

$('input[type="checkbox"]').click(function(){

if($(this).prop("checked") == true){

alert("you checked checkbox.");

}else if($(this).prop("checked") == false){

alert("you unchecked checkbox.");

}

});

});

</script>

</body>

</html>

I hope it can help you...