jQuery slideUp(), slideDown() and slideToggle() example
Published: May 26, 2010 , Updated: May 17, 2010 , Author: mkyong
jQuery comes with three handy methods to create the sliding effect easily.
- slideUp() – Hide the matched elements with slide up effect.
- slideDown() – Display the matched elements with slide down effect.
- slideToggle() – If the matched element is displayed, it will hide with a slide up effect; if hidden, it will display with a slide down effect.
Above three methods are support duration as parameter : slow, fast, or exact milliseconds. If this parameter is omitted, the default 400 milliseconds is apply.
Try it yourself
<html> <head> <script type="text/javascript" src="jquery-1.4.2.min.js"></script> <style type="text/css"> .slideDownbox, .slideUpbox, .slideTogglebox{ float:left; padding:8px; margin:16px; border:1px solid red; width:200px; height:50px; background-color:#000000; color:white; } .clear{ clear:both; } </style> </head> <body> <h1>jQuery slideUp(), slideDown() and slideToggle() example</h1> <div class="clear"> <h3>slideDown() example</h3> <div class="slideDownbox"> Click me - slideDown() </div> <div class="slideDownbox"> Click me - slideDown() </div> </div> <div class="clear"> <h3>slideUp() example</h3> <div class="slideUpbox"> Click me - slideUp() </div> <div class="slideUpbox"> Click me - slideUp() </div> </div> <div class="clear"> <h3>slideToggle() example</h3> <button id=slideToggle>slideToggle()</button> <br/> <div class="slideTogglebox"> slideToggle() </div> <div class="slideTogglebox"> slideToggle() </div> </div> <br/><br/> <div class="clear"> <button id=reset>Reset</button> </div> <script type="text/javascript"> $(".slideDownbox").click(function () { $(this).hide().slideDown('slow'); }); $(".slideUpbox").click(function () { $(this).slideUp(2000); }); $("#slideToggle").click(function () { $('.slideTogglebox').slideToggle(); }); $("#reset").click(function(){ location.reload(); }); </script> </body> </html>
Note : You can find more similar articles at - jQuery Tutorials








Thanx for that its really nice demo
[...] or JQuery experience, this turned out to be pretty easy to implement. (And I got some help from this blog post on mkyong.com.) It isn’t going to win any design awards, but it gets the job done [...]
Hello,
Loved the example, but what if i want the content to be hiden when the page is loaded?
I tried various things without success. Can you suggest something?
Use this – http://api.jquery.com/hide/
really great effect, i’ll try it on my next project, thanks man:)
It looks so amazing. I must do it on some design websites. :)
Thank you for sharing.
Great Article! I love how simple you have made it for a user to easily get a grasp on jQuery. Great code snippets. I found this article because I was doing some research for other beginner articles on jQuery. Good job and thanks again.
BTW, I have created a simple jQuery slideup and slidedown article that I feel would be targeted at very basic users, anyway let me know what you think, it’s at: http://www.tonylea.com/2010/jquery-slideup-and-slidedown/
Thanks :)