jQuery Animation How to - Fade in div element








Question

We would like to know how to fade in div element.

Answer


<!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'>
#test {<!-- w  ww .  j  a  v a2 s  . co m-->
  width: 150px;
  height: 150px;
  background-color: red;
  opacity: 0;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $('a').click(function() {
        $('#test').fadeTo('slow', 1);
    });
});
</script>
</head>
<body>
  <div id="test"></div>
  <a href="#">click</a>
</body>
</html>

The code above is rendered as follows: