jquery - Change tag on hover - replace image with text -
i have image value , want able hover on image , change text (to show image means, because image rather small)
i've tried using replacewith
doesn't work when stop hovering.
$(document).ready(function(){ $("#apples").hover(function(){ $(this).replacewith("<span id=\"apples\">apples: 10</span>"); }, function(){ $(this).replacewith("<span id=\"apples\"><img src=\"images/apples.png\" alt=\"apples\"/> 10</span>"); }); });
hopefully explained correctly. want switch out image of apple text says apples when user hovers on it.
you need replace inner html of element, otherwise original element (which has hover event listener) ceases exist:
$("#apples").hover(function(){ $(this).html("apples: 10"); }, function(){ $(this).html("<img src=\"images/apples.png\" alt=\"apples\"/> 10"); });
Comments
Post a Comment