Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

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.

#189106
npav
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");