I need to check the checked
property of a checkbox and perform an action based on the checked property using jQuery.
For example, if the age checkbox is
If you are using an updated version of jquery, you must go for .prop
method to resolve your issue:
$('#isAgeSelected').prop('checked')
will return true
if checked and false
if unchecked. I confirmed it and I came across this issue earlier. $('#isAgeSelected').attr('checked')
and $('#isAgeSelected').is('checked')
is returning undefined
which is not a worthy answer for the situation. So do as given below.
if($('#isAgeSelected').prop('checked')) {
$("#txtAge").show();
} else {
$("#txtAge").hide();
}
Hope it helps :)- Thanks.