On my website I'm displaying an image which i styled with css to be a card. With a hover effect you can flip the card (frontside is the image) and read an image description on the back side. Further I added a button "Shuffle" which replaces the image with a new one selected random out of an array.
My problem: If the new image is selected, the image description of course stays the same. Is it somehow possible to not only connect the image to an array value but also the fitting text for the description as every image needs an individual description? (Code at the bottom)
Thanks!
<body>
<div class="maincontainer">
<div class="thecard">
<div class="thefront">
<img src="images/meme1.jpg" id="picture1"/>
</div>
<div class="theback">Picture1 Description</div>
</div>
</div>
<button onClick="shuffle();">SHUFFLE</button>
<script type="text/javascript">
function shuffle(){
var images1 = [],
index1 = 0;
images1[0] = "images/meme2.jpg";
images1[1] = "images/meme3.jpg";
images1[2] = "images/meme4.jpg";
index1 = Math.floor(Math.random() * images1.length);
document.getElementById("picture1").src = images1[index1];
}
</script>
</body>