Hi,
I am using a toggle button to switch between the light and dark mode. Currently I am using this to toggle the switch to correct option if the dark mode is selected
document.getElementById("check").checked = true;
document.getElementById("check2").checked = true;
} else {
document.getElementById("check").checked = false;
document.getElementById("check2").checked = false;
}
};
and this is my toggle switch
<label for="check" class="relative h-6 w-12 cursor-pointer rounded-full bg-geraldine-500">
<input class="peer sr-only" type="checkbox" id="check" toggle-color-scheme />
<span class="absolute left-1 top-1 h-4/6 w-1/3 rounded-full bg-white transition-all duration-500 peer-checked:left-7 peer-checked:bg-dark-600 shadow-lg"></span>
</label>
It works, but since it's a window.onload function, the toggle switches position on every refresh or clicking to another page. Is there a better way to do this? I come from mostly html background.