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

Popular posts from this blog

jquery - ReferenceError: CKEDITOR is not defined -

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

java - Android – MapFragment overlay button shadow, just like MyLocation button -