I have been working on a code to toggle between dark and light mode on a webpage. While it works fine within the current page, the issue arises when I navigate to another page or refresh the current one - the mode resets back to default (light). How can I make the webpage remember the mode I choose? Below is the simple code snippet I am using to switch between CSS styles.
TOGGLE BUTTON
<i class="fa fa-toggle-on fa-2x active" id="on" style="display:none;" onclick="darkswitchoff()"></i>
<i class="fa fa-toggle-on fa-2x fa-rotate-180 inactive" id="off" onclick="darkswitchoon()"></i>
SCRIPT
<script>
$(document).ready(function(){
$('.middle').click(function() {
$('.inactive, .active').toggle();
});
});
</script>
<script>
function darkswitchoff() {
document.getElementById('mainstylesheet').href='/assets/css/main.css';
}
function darkswitchoon() {
document.getElementById('mainstylesheet').href='/assets/css/main-dark.css';
}
</script>