I have a checkbox option that when active, shows a second check. I need to make sure the second checkbox is only active if the first one is. My function shows and hides the second check according to the value of the first one, but I need it also to clear the second one when the first one is cleared and this is not working. Can you help me ? Follow my code.
$("#ck1").click(function() {
if ($("#ck1").is(':checked')) {
$("#ck2").show();
} else {
if ($("#ck2").is(':checked')) {
$("#ck2").prop('checked', false);
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div><inputtype="checkbox" id="ck1" name="ck1" />
<label for="ck1">Check 1</label>
</div>
<div style="display: none;">
<input type="checkbox" id="ck2" name="ck2" />
<label for="ck2">Check 2</label>
</div>