How to Check If Checkbox is Checked or Not in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- JQuery Chosen Multi Select Dropdown Example
- JQuery Bootbox Modal Dialog Prompt Example
- JQuery Validate File Size with Multiple File Upload Example
- Automatically Scroll to Bottom of Div JQuery Example
- How to Allow Only One Checkbox Checked at a Time in JQuery?
- How to Convert Line Breaks to br in jQuery ?
- How to Check Object is Empty or Not in JQuery?