Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created April 12, 2025 15:25
Show Gist options
  • Save thinkphp/1e7f6d306e1cb78efaacd2f90b04b970 to your computer and use it in GitHub Desktop.
Save thinkphp/1e7f6d306e1cb78efaacd2f90b04b970 to your computer and use it in GitHub Desktop.
toggle css
themeToggle.addEventListener('click', () => {
const html = document.documentElement;
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
html.setAttribute('data-theme', newTheme);
// Update the button icon
if (newTheme === 'dark') {
moonIcon.style.display = 'none';
sunIcon.style.display = 'block';
} else {
moonIcon.style.display = 'block';
sunIcon.style.display = 'none';
}
// Save user preference
localStorage.setItem('finance-tracker-theme', newTheme);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment