I'm trying to show a div upon selecting a checkbox or radio button. I'm not using the click function or anything complicated. Can anyone find my problem in my code? It should be a breeze to solve. Thanks!
$(() => {
if ($("input#checkbox").is(':checked')) {
$('#add-a-car').show();
// Code in the case checkbox is checked.
} else {
$('#add-a-car').hide();
// Code in the case checkbox is NOT checked.
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<label for="add-a-car">Add-a-Car</label>
<input type="checkbox" name="checkbox" id="checkbox">
<div id="add-a-car">
<label for="add-a-car">Pick your date</label>
<input type="text" value="pick-a-date">
</div>
Aucun commentaire:
Enregistrer un commentaire