toggle dark mode javascript
<style>
body {
background-color: white;
color: black;
}
/* DARK MODE */
.dark-mode{
background-color: black;
color: white;
}
</style>
<button class="nav-item"><a role="button" onclick="darkmode()">Toggle Me</a></button>
</script>
function darkmode() {
const wasDarkmode = localStorage.getItem('darkmode') === 'true';
localStorage.setItem('darkmode', !wasDarkmode);
const element = document.body;
element.classList.toggle('dark-mode', !wasDarkmode);
}
function onload() {
document.body.classList.toggle('dark-mode', localStorage.getItem('darkmode') === 'true');
}</script>