After creating my own webpage with a unique light switch that inverts colors, I encountered an issue with changing the color of my links. Despite setting the anchor tags to transition to a different color, it just wouldn't work.
Here is the HTML code snippet:
<nav>
<h1>My Portfolio</h1>
<ol>
<li><a title="Link to My Cover Letter & CV" href="index.html">My Cover Letter & CV</a> | </li>
<li><a title="Link to My Projects" href="">My Projects</a> | </li>
<li><a title="Link to Temp" href="">Temp</a> | </li>
<li><a title="Link to Temp" href="personalDev.html">Temp</a></li>
</ol>
</nav> <!-- Closes Nav -->
The CSS styling for the links:
/*Links*/
a, a:link, a:visited {
color: black;
text-decoration: none;
transition: 1s;
}
/*Link hovering*/
nav a:hover {
text-decoration: none;
border: solid 1px black;
border-radius: 5px;
padding: 10px;
}
As for JavaScript functionality:
document.addEventListener ("DOMContentLoaded", handleDocumentLoad);
function handleDocumentLoad() {
var offSwitch = document.getElementById("lightSwitchOff");
var onSwitch = document.getElementById("lightSwitchOn");
var border = document.getElementById("mainContent");
offSwitch.innerHTML = "Turn On Night Mode";
onSwitch.innerHTML = "Turn Off Night Mode";
onSwitch.style.display = "none";
offSwitch.addEventListener("click", lightsOff);
onSwitch.addEventListener("click", lightsOn);
function lightsOff() {
document.body.style.backgroundColor = "#000000";
document.body.style.color = "#FFFFFF";
border.style.borderColor = "#FFFFFF";
onSwitch.innerHTML = "Turn Off Night Mode";
onSwitch.style.display = "inline";
offSwitch.style.display = "none";
}
function lightsOn() {
document.body.style.backgroundColor = "#FFFFFF";
document.body.style.color = "#000000";
border.style.borderColor = "#000000";
offSwitch.innerHTML = "Turn On Night Mode";
onSwitch.style.display = "none";
offSwitch.style.display = "inline";
}
}
Additionally, I am curious about preserving the page state so that if a user toggles the light switch and refreshes the page, it remains in the same mode.