I have 2 mode switches. first for the navbar and second, for the popup when the website is first visited. Everything works fine except, in popup mode the switch doesn't move but the body has changed to dark mode / light mode.
i have tried to change the id for each switch but it still doesn't work. My main problem is, the switch in the popup doesn't move.
Can anyone handle it? where did i go wrong?
For full code, you can see in My Codepen
<div id="modeSwitcher">
<input type="checkbox" class="checkbox" id="chk" />
<label class="label" for="chk">
<i class="fas fa-moon"></i>
<div class="ball"></div>
</label>
</div>
<!-- Popup Mode -->
<div id="popupMode">
<div class="container-fluid p-0 h-100">
<div class="row h-100">
<div class="col-12 main-content">
<div id="modeChoice">
<div class="title">
<h2>Welcome</h2>
<p>
You can switch the button from light mode<br>to dark mode
</p>
</div>
<div class="choose-mode">
<div id="modeSwitcher">
<input type="checkbox" class="checkbox" id="chk" />
<label class="label" for="chk">
<i class="fas fa-moon"></i>
<div class="ball"></div>
</label>
</div>
</div>
<div id="buttonPopupMode">
<a href="#" class="btn button-primary">UNDERSTAND</a>
</div>
</div>
</div>
</div>
</div>
</div>
window.onload = function() {
$("#popupMode").delay(3000).fadeIn(500);
if (localStorage.darkMode == "true") {
document.body.classList.toggle('dark');
document.getElementById("chk").checked = true;
} else {
document.body.classList.toggle('light');
}
};
document.getElementById("chk").addEventListener('change', () => {
document.body.classList.toggle('dark');
document.body.classList.toggle('light');
localStorage.darkMode = (localStorage.darkMode == "true") ? "false" : "true";
});
$("#buttonPopupMode .button-primary").on('click', function() {
$('#popupMode').hide();
})