I've been trying to figure this out for 2 days, but I couldn't find any solutions.
What I want is, every time I check the checkbox, an element's property will change(i.e. BGcolor of the body). but it only works when the checkbox is checked, but it doesn't work when the checkbox is unchecked.
var checkboxStatus = document.getElementById("menuCheckBox");
function menuToggle() {
if (checkboxStatus.checked = true) {
document.body.style.background = "cyan";
} else {
document.body.style.background = "magenta";
}
}
menuToggle();
<input id="menuCheckBox" type="checkbox" onclick="menuToggle()"/>