If you're looking to update a CSS variable without affecting the hover color, you can achieve it like this:
:root {
--color: red;
}
.overlay-left-a {
color: var(--color);
}
To change the value of the color on :root
, you can use the following JavaScript code:
document.documentElement.style.setProperty("--color", "blue");
// Or any other color value −−−−^^^^^^
Check out the live example below:
document.querySelector("input[type=button]").addEventListener("click", (e) => {
// Get the new color from input
const color = document.getElementById("txt-color").value.trim();
// Apply the new color
document.documentElement.style.setProperty("--color", color);
});
:root {
--color: red;
}
.overlay-left-a {
color: var(--color);
}
.overlay-left-a:hover {
color: black;
}
<a href="" class="overlay-left-a">test</a>
<a href="" class="overlay-left-a">test</a>
<a href="" class="overlay-left-a">test</a>
<a href="" class="overlay-left-a">test</a>
<div>
<label>
Color name: <input type="text" id="txt-color" value="blue">
</label>
<input type="button" value="Set Color">
</div>