AdBlock Detected

We provide high-quality source code for free. Please consider disabling your AdBlocker to support our work.

Buy me a Coffee

Saved Tutorials

No saved posts yet.

Press Enter to see all results

[jQuery] Effect show() Method

By pushpam abhishek
Listen to this article
.show() is a jQuery method

jquery show effects demo

.show() is a jQuery method that displays hidden elements on your page.

Set up the HTML and CSS

In this example, we will use the method .show() to make a hidden element appear when clicking a button.

HTML and CSS for the element that is not displayed:


<style type="text/css">
#hidden-element{ display:none; }
</style>

<div id="hidden-element">Hello world</div>

HTML of the button that will make the div "#hidden-element" appear:
<input type="button" id="button-show" value="Click me" />

Set up the jQuery code

<script>
$(function(){
 $('#button-show').click(function(){
  $('#hidden-element').show();
 });
});
</script>

When the element with the id 'button-show' is clicked, the element with the id 'hidden-element' is displayed.

show() parameters and options

Duration

You can specify a duration in the show() to change the speed of the animation when the element appears on the page.

The duration can take the following values:

  • slow (200 milliseconds)
  • fast (600 milliseconds)
  • any duration in milliseconds

<style type="text/css">
#hidden-element{ display:none; }
</style>

<input type="button" id="button-show" value="Click me" />

<div id="hidden-element">Hello world</div>

<script>
$(function(){
 $('#button-show').click(function(){
  $('#hidden-element').show('slow');
 });
});
</script>

Callback

A callback is a function that is called when the animation is complete. When using show(), the callback function will be called when the element is entirely displayed on the page.

Example:

When the button below is clicked, the animation begins and then a javascript 'alert' dialog box opens when the animation is over.


<style type="text/css">
#hidden-element{ display:none; }
</style>

<input type="button" id="button-show" value="Click me" />

<div id="hidden-element">Hello world</div>

<script>
$(function(){
    $('#button-show').click(function(){
        $('#hidden-element').show( function(){alert('Animation is complete!')} );
    });
});
</script>

Do you know:-

If you like the tutorial, then please share this tutorial with your friends on social media.

Share this post

pushpam abhishek

About pushpam abhishek

Pushpam Abhishek is a Software & web developer and designer who specializes in back-end as well as front-end development. If you'd like to connect with him, follow him on Twitter as @pushpambhshk

Comments