.show()

In this chapter you will learn:

  1. Syntax and Description for .show() methods
  2. Show hidden div tags
  3. Click to show
  4. Show fast
  5. Show hidden fast
  6. Show hidden slow
  7. Show in millisecond
  8. Show normal
  9. Pass arguments.callee to show callback function
  10. Div based Dialog

Syntax and Description

.show([duration][, callback])

displays the matched elements.

  • duration (optional)A string or number determining how long the animation will run
  • callback (optional)A function to call once the animation is complete

Its return value is the jQuery object, for chaining purposes.

With no parameters, the .show() method displays an element.

$('.target').show();

Durations are given in milliseconds; higher values indicate slower animations.

The 'fast' and 'slow' strings can be supplied to indicate durations of 200 and 600 milliseconds, respectively.

If supplied, the callback is fired once the animation is complete.

We can animate any element, such as a simple image:

Show hidden div tags

<html><!-- j  a v a2s .com-->
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
           $("div:hidden").show(3000);
        });
    </script>
  </head>
  <body>
    <body>
      <span></span>
      <div style="display:none;">Hider! java2s.com</div>
      <div></div>
    </body>
</html>

Click to view the demo

Click to show

<!DOCTYPE html><!--   j a  va 2s . c om-->
<html>
<head>
<style type="text/css">
#message {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 20px;
  background-color: orange;
}

#container {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 500px;
}
</style>
<script
  src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
  $(function() {
    $("#message").click(function(e) {
      e.stopPropagation();
      $(this).hide();
    });
    $(document).click(function() {
      $("#message").show();
    });
  });
</script>
</head>
<body>
  <div id="message">This is a message.</div>
</body>
</html>

Click to view the demo

Show fast

<html><!--from   j a v a2s.  com-->
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
             $("p").show("fast")
        });
    </script>
  </head>
  <body>
    <body>
        <p style="display:none">Hello! java2s.com</p>
    </body>
</html>

Click to view the demo

Show hidden fast

<html><!--from  j  a v  a 2  s.c  o  m-->
  <head>
    <style>
      div { width:50px; height:40px; margin: 5px; float:left;background:red; }
    </style>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
          $("button").click(function () {
             $("div:hidden").show("fast");
          });
    });
    </script>
  </head>
  <body>
      <button>Show</button>
      <div></div>
      <div style="display:none;"></div>
      <div></div>
      <div></div>
      <div style="display:none;"></div>
  </body>
</html>

Click to view the demo

Show hidden slow

<html><!--from   j a  v  a2 s.co  m-->
  <head>
    <style>
      div { width:50px; height:40px; margin: 5px; float:left;background:red; }
    </style>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
          $("button").click(function () {
             $("div:hidden").show("slow");
          });
    });
    </script>
  </head>
  <body>
      <button>Show</button>
      <div></div>
      <div style="display:none;"></div>
      <div></div>
      <div></div>
      <div style="display:none;"></div>
  </body>
</html>

Click to view the demo

Show in millisecond

<html><!--from ja  va  2 s  . c om-->
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
             $("p").show(2000)
        });
    </script>
  </head>
  <body>
    <body>
        <p style="display:none">Hello! java2s.com</p>
    </body>
</html>

Click to view the demo

Show normal

<html><!--from  java  2s .  co m-->
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
             $("p").show("normal")
        });
    </script>
  </head>
  <body>
    <body>
        <p style="display:none">Hello. java2s.com</p>
    </body>
</html>

Click to view the demo

Pass arguments.callee to show callback function

<html><!--  j a v a2 s. c  om-->
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $("#showHandler").click(function () {
              $("div:eq(0)").show("fast", function () {
                $(this).next().show("fast", arguments.callee); 
              });
            });
            $("#hideHandler").click(function () {
              $("div").hide(2000);
            });
        });
    </script>
  </head>
  <body>
    <body>
      <button id="showHandler">Show</button>
      <button id="hideHandler">Hide</button>
    
      <div>A</div>
      <div>B</div>
      <div>C</div>
      <div>D java2s.com</div>
    </body>
</html>

Click to view the demo

Div based Dialog

<html><!-- ja  va 2  s . c o  m-->
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"> 
    </script>

    <script type='text/javascript'>
        $(document).ready(
          function() {
            $('input#tmpOpen').click(
              function($e) {
                $('div#myDialog').show(5000);
              }
            );
            
            $('input#tmpClose').click(
              function($e) {      
                $('div#myDialog').hide(5000);
              }
            );
          }
        );
    </script>
    <style type='text/css'>
        div#myDialog {
            display: none;
            position: absolute;
            top: 50%;
            left: 50%;
            width: 500px;
            height: 200px;
            margin: -101px 0 0 -251px;    
            border: 1px solid rgb(128, 128, 128);
        }
        
        div#tmpButtons {
            position: absolute;
            bottom: 5px;
            right: 5px;
        }
    </style>
  </head>
  <body>
     <input type='submit' id='tmpOpen' value='Open' />
     <div id='myDialog'>
       <p>
         Dialog content
       </p>
       <div id='tmpButtons'>
         <input type='submit' id='tmpClose' value='Close' />
       </div>
     </div>
  </body>
</html>

Click to view the demo

Next chapter...

What you will learn in the next chapter:

  1. Syntax and Description for .slideDown()
  2. Slide down a paragraph
  3. slideDown and slideUp
  4. Hide and Slide down
  5. Slide down and set focus
  6. Slide down fast
  7. Slide down slowly
  8. Slide down form fields
  9. Slide down in milliseconds
  10. Slide to show paragraph
  11. Animate height
Home » jQuery » Effect
.animate()
.css() does animation
.clearQueue()
.delay()
.dequeue()
.extend()
.fadeIn()
.fadeOut()
.fadeTo()
.hide()
.queue()
.show()
.slideDown()
.slideToggle()
.slideUp()
.stop()
.toggle()