javascript - jQuery swap image on hover, then replace it with original on hover off -


i using following code swap image src out on hover of child's parent. how can save original source in variable , on hover off return image original source?

      $("#parent span").hover(function(){           var currentimage = $('img', ).attr("src","images/orbs/yellowbar.png");           $('img', ).attr("src","images/yellowbar.png");           },function(){            $('img', ).attr("src",currentimage);        }); 

define currentimage outside of function:

var currentimage;  $("#parent span").hover(function() {     currentimage = $('img', this).attr("src", "images/orbs/yellowbar.png");     $('img', this).attr("src", "images/yellowbar.png"); }, function() {     $('img', this).attr("src", currentimage); }); 

Popular posts from this blog