I would like to set the color scheme based on simple CSS root variables. The JavaScript does not work: it does not see/set the root variables when one of the options are clicked. What have I overlooked to make this simple color scheme work?
const setTheme = theme => document.documentElement.className = theme;
document.getElementById('themeoptions').addEventListener('change', function() {
setTheme(this.value);
});
#themeoptions p{ /* User Interface */
display: inline-block;
text-decoration: underline;
}#themeoptions p:hover{cursor: pointer}
:root.light {
--bgr: #ddc;
--txt: #456;
}
:root.dark {
--bgr: #222;
--txt: #844;
}
:root.blue {
--bgr: #046;
--txt: #dde;
}
body {
background-color: var(--bgr);
color: var(--txt);
}
<div id="themeoptions">
<p value="light">Light</p>
<p value="dark">Dark</p>
<p value="blue">Blue</p>
</div>
<h1>Click on a theme to change the color scheme!</h1>
'change'be'click'? But then still it does not work. This is a tough one for me.