NotRankovic
New Coder
Hello,
I'm new to learning java script, I made a small script that will change the theme on my site (and icon for dark theme and light theme), but I have the following problem:
I don't know how to create cookies that when someone turns on the dark theme, they save it, and when someone refreshes the site, it loads the site in the theme the user was in last time.
Thanks!
I'm new to learning java script, I made a small script that will change the theme on my site (and icon for dark theme and light theme), but I have the following problem:
I don't know how to create cookies that when someone turns on the dark theme, they save it, and when someone refreshes the site, it loads the site in the theme the user was in last time.
Thanks!
JavaScript:
<script>
var icon = document.getElementById("icon")
icon.onclick = function() {
document.body.classList.toggle("dark-mode");
if(document.body.classList.contains("dark-mode")){
icon.src = "img/Logo/Light Mode.jpg";
}else{
icon.src = "img/Logo/Dark Mode.png";
}
}
</script>