Skip to content

Instantly share code, notes, and snippets.

@crutchcorn
Created July 18, 2022 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crutchcorn/1b69259a35f7618bf73781967ebd10d6 to your computer and use it in GitHub Desktop.
Save crutchcorn/1b69259a35f7618bf73781967ebd10d6 to your computer and use it in GitHub Desktop.
let theme = document.documentElement.className;
toggleButton(theme);
themeToggleBtn.addEventListener('click', () => {
theme = currentTheme === 'light' ? 'dark' : 'light';
toggleButton(theme);
localStorage.setItem(COLOR_MODE_STORAGE_KEY, theme)
})
const initialTheme = document.documentElement.className;
toggleButton(initialTheme);
themeToggleBtn.addEventListener('click', () => {
const currentTheme = document.documentElement.className;
document.documentElement.className =
currentTheme === 'light' ? 'dark' : 'light';
const newTheme = document.documentElement.className;
toggleButton(newTheme);
localStorage.setItem(COLOR_MODE_STORAGE_KEY, newTheme)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment