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

By Hardik Savani | March 26, 2020 | Category : jQuery


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



Tags : jQuery


Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: