Is there a way to dynamically change content on a page when a checkbox is checked, and revert it back when the checkbox is unchecked? I don't want to manually set each element's value to default in JavaScript and CSS.
<div class="switch">
<input type="checkbox" name="checkbox" id="checkbox" onchange="darkmode(this)" />
</div>
<section id="section">
<p>This is a line</p>
</section>
<script>
function darkmode(checkboxElem) {
if (checkboxElem.checked) {
document.body.style.backgroundColor = "black";
document.getElementById("checkbox").style.borderColor = "white";
document.getElementById("section").style.color ="white";
} else {
document.body.style.backgroundColor = "white";
document.getElementById("checkbox").style.borderColor = "black";
document.getElementById("section").style.color ="black";
}
}
</script>
If you have a solution for resetting all elements to their defaults without specifying individual values in CSS and JavaScript, please share. Thank you!