So I created a webpage, and I have made my own light switch where it basically inverts colours, black goes to white and vice versa but I can't seem to get my links to change colour. I want my anchor tags as well as a:visited, a:link to all change to a different colour but can't get it to work.
HTML:
<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 -->
CSS:
/*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;
}
Javascript:
document.addEventListener ("DOMContentLoaded", handleDocumentLoad);
function handleDocumentLoad() {
//Variable
var offSwitch = document.getElementById("lightSwitchOff"); //Targets div with ID lightSwitchOff
var onSwitch = document.getElementById("lightSwitchOn"); //Targets div with ID lightSwitchOn
var border = document.getElementById("mainContent"); //Targets the mainContent
offSwitch.innerHTML = "Turn On Night Mode";
onSwitch.innerHTML = "Turn Off Night Mode";
onSwitch.style.display = "none";
//Event Listener
offSwitch.addEventListener("click", lightsOff); //When clicked this action is performed
onSwitch.addEventListener("click", lightsOn); //When clicked this action is performed
//Function
function lightsOff() { /*This changes the background colour to black and makes text white*/
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() { /*This changes the background colour to a white and makes text black*/
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";
}
}
Also I was wondering if there was a way to save the page state so for example the user presses the light switch, refreshes the page and it's still the same.
:hover,:focus,:active. Also, any dynamically added contents would automatically have the correct styles.