March 3, 2013
keep current src attr so I can retrieve image
Question by mt0s
Code is like this :
$(' html body div.wrapper div.middle div.post_home:first-child a ').hover(
function() {
$(' html body div.wrapper div.middle div.post_home:first-child a > img ').attr("src", "http:/site/test1.png");
},
function() {
$('html body div.wrapper div.middle div.post_home:first-child a > img ').attr("src", "currentSrc");
});
I just need to keep the src value of the image before the change so on mouseleave I can retrieve the image and display it.
Answer by Starx
Backup your src attrivute at the start of your event before changing it. And use it when you want to go to back.
var currentSrc;
$('.post_home:first-child a ').hover(function() {
currentSrc = $('.post_home:first-child a > img').attr("src");
$('.post_home:first-child a > img ').attr("src", "http:/site/test1.png");
}, function() {
$('.post_home:first-child a > img').attr("src", currentSrc);
});
Note: I edited your selectors because what you have is more than necessary.