I am trying to make the text switch based on the image that is hovered over, but I am having some troubles, the code that I am using is:
$("#myImg").hover(
function () {
$('#myText1').css('display','inline');
$('#myText').css('display','none');
},
function () {
$('#myText1').css('display','none');
$('#myText').css('display','inline');
},
I am not sure why this doesn’t work
There should not be the final comma as this causes a syntax error. You are also missing the closing parentheses for the call to
.hover:It’s generally better to use
.showand.hideinstead of using.cssdirectly unless you have some reason to do so (e.g. the default display of the element is different than what you want it to be when it’s shown). The two similar ID names are also confusing.