How to check whether a checkbox is checked in jQuery?

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 checked, then I need to show a textbox to enter age, else hide the textbox.

But the following code returns false by default:


if ($('#isAgeSelected').attr('checked')) { $("#txtAge").show(); } else { $("#txtAge").hide(); }

[removed][removed] <input type="checkbox" id="isAgeSelected"/>

Age is selected


In Progress 07-12-2019 Zeeshan 699

Please briefly explain why you feel this question should be reported .

Answers (0)

Leave An Answer

app logo

Download Our App!

Enjoy all the features. Browse jobs, articles, questions, scholarships and many more! in just one App