prop()
method & :checked
selectorThe following section describes how to track the status of checkboxes whether it is checked or not using the jQuery prop()
method as well as the :checked
selector.
<script>
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
if($(this).prop("checked") == true){
console.log("Checkbox is checked.");
}
else if($(this).prop("checked") == false){
console.log("Checkbox is unchecked.");
}
});
});
</script>
You can also use the jQuery :checked
selector to check the status of checkboxes. The :checked
selector specifically designed for radio button and checkboxes.
Let's take a look at the following example to understand how it basically works:
<script>
$(document).ready(function(){
$('input[type="checkbox"]').click(function(){
if($(this).is(":checked")){
console.log("Checkbox is checked.");
}
else if($(this).is(":not(:checked)")){
console.log("Checkbox is unchecked.");
}
});
});
</script>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to Trigger a Click on a Link Using jQuery
Use the jQuery click() Method You can...How to get last inserted id in Laravel 8
When you insert any record in database,...JavaScript vs jQuery Differences
When new developer starts learning in We...How to Switch PHP versions using Command Line in Ubuntu
You might need multiple PHP version for...How to get single value from an array in PHP
Use the Array Key or Index If you wan...