Skip to content

Instantly share code, notes, and snippets.

@crutchcorn
Created March 26, 2023 07: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/8de3f1183da6a884c3bf67b16430f834 to your computer and use it in GitHub Desktop.
Save crutchcorn/8de3f1183da6a884c3bf67b16430f834 to your computer and use it in GitHub Desktop.
Used in a Twitter thread
// ...
let theme = document.documentElement.className;
toggleButtonIcon(theme);
themeToggleBtn.addEventListener('click', () => {
theme = theme === 'light' ? 'dark' : 'light';
toggleButtonIcon(theme);
});
// ...
const initialTheme = document.documentElement.className;
toggleButtonIcon(initialTheme);
themeToggleBtn.addEventListener('click', () => {
const currentTheme = document.documentElement.className;
document.documentElement.className =
currentTheme === 'light' ? 'dark' : 'light';
const newTheme = document.documentElement.className;
toggleButtonIcon(newTheme);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment