I'm trying (with no success) to create a checkbox that changes some style properties of the body when checked, something like this:
<script>
const x = document.getElementById('y');
if (x.checked == true) {
document.body.style.setProperty('property', 'value');
} else {
document.body.style.setProperty('property', 'value');
}
</script>
What am I doing wrong? 🤔
Thanks in advance!
bodyelement, not the checkbox itself.if(...)you tell the computer to check thecheckedvalue ofx, after that is done he will continue doing other things. He won't check again (if you aren't telling him to do so)bodyby changing its class