i got some code from the internet
It work well in Desktop & tablet , but the toggle seems not working in mobile . (sun switch to moon)
Do anyone can help with this problem
Here is the code :
"
function setThemeFromCookie() {
const themeState = document.getElementById(‘content’);
themeState.className = isThemeSelected() ? ‘dark-mode’ : ‘light-mode’;
}
function setThemeSwitchState() {
document.getElementById(‘toggleTheme’).checked = isThemeSelected();
}
function isThemeSelected() {
return document.cookie.match(/theme=dark/i) != null;
}
function toggleTheme() {
const themeState = document.getElementById(‘content’);
const currentState = themeState.className;
const newState = themeState.className == ‘dark-mode’ ? ‘light-mode’ : ‘dark-mode’;
themeState.className = newState;
document.cookie = ‘theme=’ + (newState == ‘light-mode’ ? ‘light’ : ‘dark’);
}
(function() {
setThemeFromCookie();
setThemeSwitchState();
document.getElementById(‘toggleTheme’).onchange=toggleTheme;
})();
"