How to check if checkbox is checked or not in JQuery?

Admin   Jquery   44  2020-08-11 11:46:44

Hi Dev,

Here, i will show you how to works jquery check if checkbox is checked or not. you can see how to check checkbox is checked or not in jquery on button click. Here you will learn jquery get checkbox value if checked.

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...