Color Changing Links
Inject variety into your UI. This script generates random RGB values to change link colors on the fly, creating a vibrant user experience.
Copy the Script
<script>
function setRandomColor(link) {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
link.style.color = color;
}
function resetLinkColor(link) {
link.style.color = ""; // Revert to CSS default
}
</script>
<a href="#" onmouseover="setRandomColor(this)" onmouseout="resetLinkColor(this)">Hover Me</a>
Frequently Asked Questions
Yes. Instead of generating a random hex code, you can create an array of your brand colors (`['#FF0000', '#00FF00']`) and pick from that list.
Yes. The `onmouseout` event resets the link color back to its original state (or standard link blue/black).
Yes. You can use `document.querySelectorAll('a')` to loop through every link on the page and attach the event listeners automatically.