jQuery Style How to - Add border to image on hover








Question

We would like to know how to add border to image on hover.

Answer


<!-- w w w.  j a  va 2s. c  om-->
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<style type='text/css'>
.Hover {
  border: 1px solid #000;
}
</style>
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
    $("#imgBorder img").hover(
        function() { $(this).addClass("Hover"); },
        function() { $(this).removeClass("Hover"); }
    );
});//]]>  
</script>
</head>
<body>
  <div id="imgBorder">
    <img src="http://www.java2s.com/style/download.png" />
  </div>
</body>
</html>

The code above is rendered as follows: