I'm trying to use a dark theme and light theme on my webpage, but I can't find a way to toggle them with just one button (so 1st click of the button turns on the dark theme and 2nd time turns it off). I would prefer to be able to do this without the use of a third-party JavaScript library. I have found a way to do this with an <option>
element but that isn't the "toggle button" I want:
<button onclick=getTheme() id=themeToggle>Click to use this theme.</button>
<select id="select">
<option>Dark Theme</option>
<option>Revert To Original</option>
</select>
and
function getTheme () {
function changeTheme (Theme) {
document.getElementById('style').setAttribute('href', Theme);
}
var index = document.getElementById("select").selectedIndex;
switch (index) {
case 0:
changeTheme('css/dark.css');
break;
case 1: changeTheme('css/main.css');
}
}
Thanks for your help!