Hide, Show, Toggle, Slide, Fade, and Animate. WOW!
Because time is valuable, we deliver quick and easy learning.
At W3Schools, you can study everything you need to learn, in an accessible and handy format.
Click Here to Show/Hide Panel
jQuery hide()
Demonstrates a simple jQuery hide() method.
jQuery hide()
Another hide() demonstration. How to hide parts of text.
jQuery
slideToggle()
Demonstrates a simple slide panel effect.
jQuery
fadeTo()
Demonstrates a simple jQuery fadeTo() method.
jQuery
animate()
Demonstrates a simple jQuery animate() method.
With jQuery, you can hide and show HTML elements with the hide() and show() methods:
Both hide() and show() can take the two optional parameters: speed and callback.
Syntax:
$(selector).hide(speed,callback)
$(selector).show(speed,callback)
The speed parameter specifies the speed of the hiding/showing, and can take the following values: "slow", "fast", "normal", or milliseconds:
The callback parameter is the name of a function to be executed after the
hide (or show) function completes. You will learn more about the callback
parameter in the next chapter of this tutorial.
The jQuery toggle() method toggles the visibility of HTML elements using the show() or hide() methods.
Shown elements are hidden and hidden elements are shown.
Syntax:
$(selector).toggle(speed,callback)
The speed parameter can take the following values: "slow", "fast", "normal", or milliseconds.
The callback parameter is the name of a function to be executed after the hide (or show) method completes.
The jQuery slide methods gradually change the height for selected elements.
jQuery has the following slide methods:
$(selector).slideDown(speed,callback)
$(selector).slideUp(speed,callback)
$(selector).slideToggle(speed,callback)
The speed parameter can take the following values: "slow", "fast", "normal", or milliseconds.
The callback parameter is the name of a function to be executed after the function completes.
The jQuery fade methods gradually change the opacity for selected elements.
jQuery has the following fade methods:
$(selector).fadeIn(speed,callback)
$(selector).fadeOut(speed,callback)
$(selector).fadeTo(speed,opacity,callback)
The speed parameter can take the following values: "slow", "fast", "normal", or milliseconds.
The opacity parameter in the fadeTo() method allows fading to a given opacity.
The callback parameter is the name of a function to be executed after the function completes.
The syntax of jQuery's method for making custom animations is:
$(selector).animate({params},[duration],[easing],[callback])The key parameter is params. It defines the CSS properties that will be animated. Many properties can be animated at the same time:
The second parameter is duration. It specifies the speed of the
animation. Possible values are "fast", "slow", "normal", or milliseconds.
|
HTML elements are positioned static by default and cannot be moved. To make elements moveable, set the CSS position property to fixed, relative or absolute. |
Here are some examples of effect functions in jQuery:
| Function | Description |
|---|---|
| $(selector).hide() | Hide selected elements |
| $(selector).show() | Show selected elements |
| $(selector).toggle() | Toggle (between hide and show) selected elements |
| $(selector).slideDown() | Slide-down (show) selected elements |
| $(selector).slideUp() | Slide-up (hide) selected elements |
| $(selector).slideToggle() | Toggle slide-up and slide-down of selected elements |
| $(selector).fadeIn() | Fade in selected elements |
| $(selector).fadeOut() | Fade out selected elements |
| $(selector).fadeTo() | Fade out selected elements to a given opacity |
| $(selector).animate() | Run a custom animation on selected elements |
For a full jQuery effect reference, please go to our
jQuery Effect Reference.
| WEB HOSTING |
|---|
| Best Web Hosting |
| PHP MySQL Hosting |
| Best Hosting Coupons |
| UK Reseller Hosting |
| Cloud Hosting |
| Top Web Hosting |
| $7.95/mo SEO Hosting |
| Premium Website Design |
| WEB BUILDING |
|---|
| XML Editor - Free Trial! |
| FREE Website BUILDER |
| Free Website Templates Free CSS Templates |
| Make Your Own Website |
| W3SCHOOLS EXAMS |
|---|
|
Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP |
| W3SCHOOLS BOOKS |
|---|
|
New Books: HTML, CSS JavaScript, and Ajax |
| STATISTICS |
|---|
|
Browser Statistics Browser OS Browser Display |
| SHARE THIS PAGE |
|---|