jQuery Style How to - Change opacity on hover








Question

We would like to know how to change opacity on hover.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.9.1.js'></script>
<style type='text/css'>
#menu div {<!--from   ww  w  .j a  v  a  2s  .co  m-->
  opacity: 0.7;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $("#menu DIV").hover(
      function () {
        $(this).css({ opacity: 1 });
          console.log($(this));
      },
      function () {
       $(this).css({ opacity: 0.4 });
      }
    );
});
</script>
</head>
<body>
  <div id="menu">
    <div>Testing...</div>
  </div>
</body>
</html>

The code above is rendered as follows: