jQuery Method How to - Use fadeOut() to hide an element








Question

We would like to know how to use fadeOut() to hide an element.

Answer


<!--from  w w w  .j a va 2s . c  o m-->
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.7.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){
    $(document).ready(function() {
      $("#onoff").click(function(){
        $("#tools").fadeOut(2000);
      });
    });
});
</script>
</head>
<body>
  <div id="tools">This is the tools container. watch it fade.</div>
  <a class="navtab" href="#" id="onoff">Forum Tools</a>
</body>
</html>

The code above is rendered as follows: