I'm struggling to create a versatile checkbox that will toggle the display of a div from none to block when checked, and back to none when unchecked.
I attempted to implement a conditional statement:
$("#customCheck1").on("change", function() {
if ($(this).is(":checked") || document.getElementById("Reload").style.display = "none") {
$('#lblauto').text("Auto Reload ON")
document.getElementById("Reload").style.display = "block";
} else {
$('#lblauto').text("Auto Reload OFF")
document.getElementById("Reload").style.display = "none";
}
})
However, it seems to not be working as expected.
Below are the necessary codes:
HTML (Checkbox):
<div class="custom-control custom-checkbox" id="checkasd">
<input type="checkbox" class="custom-control-input" id="customCheck1">
<label class="custom-control-label" for="customCheck1" id="lblauto"><span>Auto Reload OFF<span></label>
</div>
JQuery:
$("#customCheck1").on("change", function() {
if ($(this).is(":checked")) {
$('#lblauto').text("Auto Reload ON")
document.getElementById("Reload").style.display = "block";
} else {
$('#lblauto').text("Auto Reload OFF")
}
})
I am using Bootstrap v4.3.1