I have an images folder. Within this folder, I have several images of two types; one png and one gif. The displayed image is the png version. On an image hover, I need to replace it with its gif version. And when hover is out, put the png version back in place.
I currently have the following which works
$(".image-container").mouseover(function () {
var imgName = $(this).find('img').attr('src');
var img2 = imgName.substring(0, imgName.lastIndexOf("."));
$(this).find('img').attr("src", img2+".gif");
}).mouseout(function () {
var imgName = $(this).find('img').attr('src');
var img2 = imgName.substring(0, imgName.lastIndexOf("."));
$(this).find('img').attr("src", img2+".png");
});
It works, but I dont like the way I am repeating things. Is there any way to make this more efficient?
Thanks