Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change image url on div hover instead image hover

Tags:

html

jquery

hover

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!

like image 644
Sanjeev Kumar Avatar asked Jun 09 '26 02:06

Sanjeev Kumar


1 Answers

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");}
);
like image 73
mplungjan Avatar answered Jun 10 '26 17:06

mplungjan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!