I have developed a script that updates the class attribute of the body element on my website when an option is selected from a dropdown menu. However, I am facing an issue where it overrides the existing dark mode attribute.
The purpose of this script is to modify the color scheme of the website and store the user's preference in local storage.
How can I resolve this conflict?
function updateTheme(value) {
var themes = {
chb: "griegos",
cj: "romanos",
hv: "celtas"
};
document.getElementById("body").setAttribute("class", themes[value]);
}
.griegos {background: orange}
.romanos {background: purple}
.celtas {background: green}
<body id="body" class="griegos dark">
<select class="forminput" onchange="updateTheme(this.value)"><option value="chb">Camp Half-Blood</option><option value="cj">Camp Jupiter</option><option value="hv">Hotel Valhalla</option></select>