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 call a function repeatedly after fixed time interval in jQuery
Use the JavaScript setInterval() method...Laravel 8 get all Files in Directory Example
You may want to get images from server a...Laravel 7.x - Multiple Images Upload with Preview Example
In this article, i will let you ken ajax...How to Get the First Element of an Array in PHP
Use the PHP array_values() Function I...How to find number of characters in a string in PHP
Use the PHP strlen() function...