I am making a Website for my Uni project which requires 5 pages.
This is my code for setting dark mode in the home page, but when I go to the second page I need to manually press the button to get the dark mode on again rather than it sustaining the information from the home page.
<img src="DM.png" id="icon">
</div>
<script type="text/javascript">
var icon = document.getElementById("icon");
icon.onclick = function() {
document.body.classList.toggle("darktheme");
if (document.body.classList.contains("darktheme")) {
icon.src="LM.png";
}else
icon.src="dm.png";
}
</script>