I’m trying to use javascript to show the caption of an image only when it’s being hovered, and have a default caption displayed when no image is hovered.
<ul class="logos">
<li class="image-1"></li>
<li class="image-2"></li>
<li class="image-3"></li>
<li class="image-4"></li>
<li class="image-5"></li>
</ul>
<div class="captions">
<p>Default caption</p>
<p>This is a caption for the first logo</p>
<p>This is a caption for the second logo</p>
<p>This is a caption for the third logo</p>
<p>This is a caption for the fourth logo</p>
<p>This is a caption for the fifth logo</p>
</ul>
Any advice on how I could implement such an effect with javascript?
There’s a better way to structure your page:
UPDATED:
Hadn’t spotted that the image tags were malformed? – I’ve rewritten it as a list of images.
If your want li elements then change
alttotitle(in the elements and the code).