I have been experimenting with some JavaScript code to create a pop-up box that appears when you hover over images. However, I have encountered an issue where it only works for one image. I suspect this is because I have used IDs instead of classes, but I'm not entirely sure. Here is the code snippet I have written:
JavaScript
var e = document.getElementById('parent');
e.onmouseover = function() {
document.getElementById('popup').style.display = 'inline';
}
e.onmouseout = function() {
document.getElementById('popup').style.display = 'none';
}
HTML
<img id="parent" src="img/Fruits.png" alt="Fruit">
<div id="popup">
<h5>
Apple:
</h5>
<h5 class="fruitDescription">
Apples taste good
</h5>
</div>
CSS
#popup {
display: none;
position: absolute;
background: #000;
opacity: 0.85;
border-radius: 5px;
width: 500px;
height: 382px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
margin-top: -105px;
margin-left: 40px;
color: #1E90FF;
}
#popup:before{
content: "";
position: absolute;
top: 60px;
left: -25px;
z-index: 1;
border: solid 15px transparent;
border-right-color: black;
color: #1E90FF;
}
I suspect the issue lies with using IDs in my code. I am currently exploring ways to achieve the same functionality for multiple images.
Thank you.