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(); } How do I successfully query the checked property? Answer: This worked for me: $get("isAgeSelected ").checked == true Where isAgeSelected is the id
undefined
Setting “checked” for a checkbox with jQuery? I'd like to do something like this to tick a checkbox using jQuery: $(".myCheckBox").checked(true); or $(".myCheckBox").selected(true); Does such a thing exist? Answer: jQuery 1.6+ Use the new .prop() method: $('.myCheckbox').prop('checked', true); $('.myCheckbox').prop('checked', false); jQuery 1.5.x and below The .prop() method is not available, so you need to use .attr(). $('.myCheckbox').attr('checked', true); $('.myCheckbox').attr('checked', false); Note that this is the approach used by jQuery's unit tests prior to version 1.6 and is preferable to using $('.myCheckbox').removeAttr('checked'); since the latter will, if the box was initially checked, change the
undefined
How do I check if 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(); } How do I successfully query the checked property? Answer: This worked for me: $get("isAgeSelected ").checked == true Where isAgeSelected is the