Created
April 12, 2025 15:25
-
-
Save thinkphp/1e7f6d306e1cb78efaacd2f90b04b970 to your computer and use it in GitHub Desktop.
toggle css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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