In summary, I’m trying to hide the text next to an image when the web page loads and then display the text when the user hovers over the corresponding image.
I can’t seem to get it to display the text. Here’s the code:
JavaScript
x
6
1
<section class = muliticolumn >
2
<img class="menuSmall" src="../images/margherita.png" onmouseover="showMargTopp()">
3
<h2>Margherita</h2>
4
<p id="margTopp">Tomato, mozzarella and basil</p>
5
</section>
6
This is the code for the image and text.
JavaScript
1
2
1
#margTopp{display:none;}
2
CSS.
JavaScript
1
4
1
function showMargTopp() {
2
document.getElementByID("margTopp").style.display="block";
3
}
4
JavaScript.
I’ve tried a couple different things but I can’t seem to get it to work. Thanks for any help.
Advertisement
Answer
ID should be Id in your function.
JavaScript
1
4
1
function showMargTopp() {
2
document.getElementById("margTopp").style.display="block";
3
}
4
If you want it to be hidden again when you stop hovering, you will need another function for the onmouseout
event.
JavaScript
1
4
1
function hideMargTopp() {
2
document.getElementById("margTopp").style.display="none";
3
}
4
A simpler solution to this would be to use CSS :hover