diff --git a/static/js/switchcss.js b/static/js/switchcss.js index d2d744e..f6aec2a 100644 --- a/static/js/switchcss.js +++ b/static/js/switchcss.js @@ -3,13 +3,21 @@ const THEME_KEY = "ZULMA_THEME"; let theme = localStorage.getItem(THEME_KEY); if (theme) { changeTheme(theme); - document.querySelectorAll('#theme-select>option').forEach(element => { - if (element.value === theme) { - element.selected = 'selected'; - } - }); + window.addEventListener('DOMContentLoaded', () => { + document.querySelectorAll('#theme-select>option').forEach(element => { + if (element.value === theme) { + element.selected = 'selected'; + } + }); + }); } +window.addEventListener('DOMContentLoaded', () => { + document.getElementById('theme-select').onchange = function () { + changeTheme(this.value); + } +}); + function changeTheme(themeName) { let alternates = []; @@ -33,10 +41,4 @@ function changeTheme(themeName) { function saveTheme(themeName) { localStorage.setItem(THEME_KEY, themeName); -} - -window.addEventListener('load', () => { - document.getElementById('theme-select').onchange = function () { - changeTheme(this.value); - } -}); \ No newline at end of file +} \ No newline at end of file