jQuery Page Widget How to - Make text change color when i hover the image








Question

We would like to know how to make text change color when i hover the image.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.5.2.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from w  w  w .  java2s  . c om-->
    $("img").hover(function(){
      $(this).parent().next("a").css("color","red"); 
    });
    $("img").mouseout(function(){
      $(this).parent().next("a").css("color",""); 
    });
});
</script>
</head>
<body>
  <li><a href="#"><img src="http://www.java2s.com/style/download.png"></a> <a href="#">TEXT</a></li>
</body>
</html>

The code above is rendered as follows: