Home › Forums › JavaScript › How to change image on hover of a different div jQuery. › Reply To: How to change image on hover of a different div jQuery.
November 24, 2014 at 10:58 am
#189106
Participant
UPDATE: Figured it out, I’ll post my jQuery incase anyone else is looking to do something like this.
$(document).ready(function(){
$(".div").hover(function() {
$( '.img-class' ).attr("src","new-img.png");
}, function() {
});
</code
Just apply a class to your image tag and target it in your jQuery, on .hover of the div specified on line 2 the src attribute of your img will be changed to the new one, if you want to switch it back to your old img when your mouse leaves the div just add this code below the last function().
$( '.div' ).attr("src","old-img.png");