I need to show/hide div based on checkbox value by jquery:
- when webpage is loaded and
- when checkbox value is changed (on click/on change)
I found few ways how to solve these problems separately, but does exists a simple way how to handle both group of events at once?
Example (change):
<input class="form-check-input" type="checkbox" id="checkbox1" checked>
<div id="autoUpdate" class="autoUpdate">
Example
</div>
<script>
$(document).ready(function(){
$('#checkbox1').change(function(){
if(this.checked)
$('#autoUpdate').show();
else
$('#autoUpdate').hide();
});
});
</script>
Aucun commentaire:
Enregistrer un commentaire