I am trying to change the url of image on mouseover, its working fine but what I am trying is, hover on div instead of image and change the image url
following the jQuery I have:
$(".logo > img").on({
"mouseover" : function() {
this.src = 'images/logo-white.png';
},
"mouseout" : function() {
this.src='images/logo-black.png';
}
HTML
<div class="logo">
<img src="images/logo-white.png">
</div>
How do I make it on div hover? please help!
If this is the HTML
<div class="logo">
<img src="images/logo-white.png">
</div>
then this will work:
$(".logo").on({
"mouseover": function() {
$(this).find("img").attr("src", "images/logo-white.png");
},
"mouseout": function() {
$(this).find("img").attr("src", "images/logo-black.png");
}
});
Alternative: .hover - which is using less }
$(".logo").hover(
function() {$(this).find("img").attr("src", "images/logo-white.png");},
function() {$(this).find("img").attr("src", "images/logo-black.png");}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With