I want to show an email field only if a checkbox is checked.
If the checkbox is not checked the email field must be hidden.
Here is my code:
$('#chkbx').click(function () {
var $this = $(this);
if ($this.is(':checked')) {
$('.email').hide();
$('.email').remove();
} else {
$('.email').show();
}
});
<div class="form-group">
<div class="col-xs-offset-3 col-xs-8">
<label class="checkbox-inline col-xs-10">
<input type="checkbox" ID="chkbx"> Email me the report when ready.
</label>
</div>
</div>
<div class="form-group email">
<div class="col-xs-offset-3 col-xs-8">
<div class="col-xs-8">
<input type="text" class="form-control " placeholder="Enter your email">
</div>
</div>
</div>