Hide or show element if checkbox input is checked


For example, if you wish to hide or show a textbox based on if a checkbox is selected:

HTML:

<input id="showTextbox" type="checkbox" />
<textarea id="textbox"></textarea>

JS

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

Leave a Reply

Your email address will not be published. Required fields are marked *