jQuery Method How to - Use slideToggle() to show with sliding








Question

We would like to know how to use slideToggle() to show with sliding.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-2.1.0.js'></script>
<style type='text/css'>
#show {<!--  w  w  w  . j ava  2 s.co  m-->
  display: none;
  margin-top: 20px;
}
</style>
<script type='text/javascript'>
$(window).load(function(){
    $(document).on("click", "#clickme", function() {
        $("#show").slideToggle();
    });
});
</script>
</head>
<body>
  <input type="button" id="clickme" value="Clickhere">
  <div id="show">
    <a>Hello</a>
  </div>
</body>
</html>

The code above is rendered as follows: