Filter by Tags

How to check weather a checkbox is checked in jquery?

Votes

1

1 0

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();
}



Manish Rawat
Posted on : Tue, Dec 26, 2017
Views : 145
Comments

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Answers (1)

Approved Answer

1

you should use is() Function 

if($("#isAgeSelected").is(':checked'))
$("#txtAge").show(); // checked
else
$("#txtAge").hide(); // unchecked



Kushal Kumar
Tue, Dec 26, 2017
Loading...
Comments

Edit Answer

Submit
This answer will permanently deleted. Do you really want to delete this Answer ?
To Add your Answer Please
LogIn | SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp