Home › Forums › CSS › remove an image and add a new image on mouse hover › Re: remove an image and add a new image on mouse hover
November 18, 2009 at 3:47 pm
#66780
Member
I would do it using jQuery, if you can have it available in your project… It would be something along the lines of:
Code:
$(“img”).hover(function(){
$(this).attr(“src”, “images/newImage.png”);
}, function(){
$(this).attr(“src”, “images/oldImage.png”);
};
});
$(this).attr(“src”, “images/newImage.png”);
}, function(){
$(this).attr(“src”, “images/oldImage.png”);
};
});
Alternatively (and probably better depending on what you’re trying to achieve), you could use a <div> or <a> element with a background image, and use CSS sprites + jQuery to get those same results…