Is there any way to save a DOM manipulated element?
I wrote some basic JavaScript Code, it's checking if the dark mode is on or not.
function systemTheme() {
var darkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (darkMode === true){
document.getElementById('headerMainMenu').style.backgroundColor = 'black';
} else {
document.getElementById('headerMainMenu').style.backgroundColor = 'white';
}
}
You can start the function systemTheme
with a button.
<div>
<button onclick="systemTheme()">Click Me</button>
</div>
The problem is: I click the button and the headerMainMenu
is black, but when I open another HTML file with an a
tag, the color is changing back.
The color is black in the index.html
but normal in the about.html
.
Both are connected to the JavaScript file.