I am trying to make it so that clicking each randomize images will link to the respective url that it belongs to, i.e. clicking on facebook image will go to facebook.com, and clicking on twitter will go to twitter.com
Currently my code here is:
<p id="background" style="width:12%;height:23%"></p>
<script type="text/javascript">
function randomImage() {
var fileNames = [
"image1.png",
"image2.jpg",
"image3.png"
];
var randomIndex = Math.floor(Math.random() * fileNames.length);
document.getElementById('background').style.background = 'url(' +
fileNames[randomIndex] + ')';
}
randomImage();
setInterval(randomImage, 2000);
</script>
I've tried adding in various other methods to add the url, however my image will always disappear after adding. Thank you for looking at this post.