I've been working on incorporating a Dark Mode feature into my website. I started by creating an HTML file with the CSS set in "white mode." Then, I added a button with the attribute onclick="enableDarkMode()" and defined the function as follows:
function enableDarkMode() {
if (document.body.style === "background-color: black;") {
// disable dark mode
} else {
document.body.style = "background-color: black;";
Array.from(document.getElementsByTagName("a")).forEach(e => {
e.style.color = "white";
});
document.getElementsByTagName("h1")[0].style.color = "white";
document.getElementsByTagName("img")[0].style = "box-shadow: 0px 4px 6px 2px #404040;";
}
}
After running the code and clicking on Enable Dark Mode, I noticed that only the background color changed and the text color remained unchanged despite having the style attribute set to "color: white."
If you want to take a look at the full code, here's the link: https://codepen.io/anonhexo/pen/WNGmevq