• support@answerspoint.com

Check checkbox checked property


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')) {
} else {

How do I successfully query the checked property?



How do I successfully query the checked property?

The checked property of a checkbox DOM element will give you the checked state of the element.

Given your existing code, you could therefore do this:

if(document.getElementById('isAgeSelected').checked) {
} else {

However, there's a much prettier way to do this, using toggle:


$('#isAgeSelected').click(function() {
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox" id="isAgeSelected"/>
<div id="txtAge" style="display:none">Age is something</div>
  • answered 7 years ago
  • G John


Use jQuery's is() function:

    $("#txtAge").show();  // checked
    $("#txtAge").hide();  // unchecked
  • answered 7 years ago
  • Sunny Solu

Your Answer

    Facebook Share        
  • asked 7 years ago
  • viewed 1596 times
  • active 7 years ago

Best Rated Questions