theme-change-final.html
HTML document, ASCII text
1<!DOCTYPE html> 2<html data-theme="light"> 3 4<head> 5<style type="text/css"> 6html[data-theme=light] { 7background: #fff; 8color: #000; 9--buttonBackground: #fefefe; 10--buttonBorder: #ccc; 11--buttonColor: #001; 12} 13html[data-theme=dark] { 14background: #000; 15color: #fff; 16--buttonBackground: #101010; 17--buttonBorder: #333; 18--buttonColor: #fff; 19} 20html[data-theme=gamer] { 21background: #f00; 22color: #00f; 23--buttonBackground: #050; 24--buttonBorder: #0a0; 25--buttonColor: #0f0; 26} 27button { 28background: var(--buttonBackground); 29border: var(--buttonBorder) solid 3px; 30color: var(--buttonColor); 31} 32</style> 33</head> 34 35<body> 36<button id="themeSwitch">Switch Theme</button> 37This is epic! 38<script type="text/javascript"> 39console.log("Changing theme") 40const themes = ["light", "dark", "gamer"]; 41document.querySelector("#themeSwitch").addEventListener("click", function() { 42console.log("Changing theme") 43let curTheme = themes.indexOf(document.documentElement.dataset.theme); 44if (curTheme + 1 >= themes.length) { 45document.documentElement.dataset.theme = themes[0]; 46return; 47} 48console.log("asfd") 49document.documentElement.dataset.theme = themes[curTheme + 1]; 50}) 51</script> 52</body> 53 54</html>