jQuery API

.show()

.show( ) Returns: jQuery

Description: Display the matched elements.

  • version added: 1.0.show()

  • version added: 1.0.show( duration [, callback] )

    durationA string or number determining how long the animation will run.

    callbackA function to call once the animation is complete.

  • version added: 1.4.3.show( [duration] [, easing] [, callback] )

    durationA string or number determining how long the animation will run.

    easingA string indicating which easing function to use for the transition.

    callbackA function to call once the animation is complete.

With no parameters, the .show() method is the simplest way to display an element:

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

The matched elements will be revealed immediately, with no animation. This is roughly equivalent to calling .css('display', 'block'), except that the display property is restored to whatever it was initially. If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline.

Note: If using !important in your styles, such as display: none !important, it is necessary to override the style using .css('display', 'block !important') should you wish for .show() to function correctly.

When a duration is provided, .show() becomes an animation method. The .show() method animates the width, height, and opacity of the matched elements simultaneously.

Durations are given in milliseconds; higher values indicate slower animations, not faster ones. The strings 'fast' and 'slow' can be supplied to indicate durations of 200 and 600 milliseconds, respectively.

As of jQuery 1.4.3, an optional string naming an easing function may be used. Easing functions specify the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called swing, and one that progresses at a constant pace, called linear. More easing functions are available with the use of plug-ins, most notably the jQuery UI suite.

If supplied, the callback is fired once the animation is complete. This can be useful for stringing different animations together in sequence. The callback is not sent any arguments, but this is set to the DOM element being animated. If multiple elements are animated, it is important to note that the callback is executed once per matched element, not once for the animation as a whole.

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

<div id="clickme">
  Click here
</div>
<img id="book" src="book.png" alt="" width="100" height="123" />
With the element initially hidden, we can show it slowly:
$('#clickme').click(function() {
  $('#book').show('slow', function() {
    // Animation complete.
  });
});

Additional Notes:

  • All jQuery effects, including .show(), can be turned off globally by setting jQuery.fx.off = true, which effectively sets the duration to 0. For more information, see jQuery.fx.off.

Examples:

Example: Animates all hidden paragraphs to show slowly, completing the animation within 600 milliseconds.

<!DOCTYPE html>
<html>
<head>
  <style>
      p { background:yellow; }
      </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <button>Show it</button>

      <p style="display: none">Hello  2</p>
<script>
    $("button").click(function () {
    $("p").show("slow");
    });
    </script>

</body>
</html>

Demo:

Example: Show the first div, followed by each next adjacent sibling div in order, with a 200ms animation. Each animation starts when the previous sibling div's animation ends.

<!DOCTYPE html>
<html>
<head>
  <style>
  div { background:#def3ca; margin:3px; width:80px;
  display:none; float:left; text-align:center; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
  <button id="showr">Show</button>
  <button id="hidr">Hide</button>
  <div>Hello 3,</div>

  <div>how</div>
  <div>are</div>
  <div>you?</div>
<script>
$("#showr").click(function () {
  $("div").first().show("fast", function showNext() {
    $(this).next("div").show("fast", showNext);
  });
});

$("#hidr").click(function () {
  $("div").hide(1000);
});
</script>

</body>
</html>

Demo:

Example: Show all span and input elements with an animation. Change the text once the animation is done.

<!DOCTYPE html>
<html>
<head>
  <style>
  span { display:none; }
  div { display:none; }
  p { font-weight:bold; background-color:#fcd; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  
<button>Do it!</button>
<span>Are you sure? (type 'yes' if you are) </span>
<div>
  <form>
    <input type="text"  value="as;ldkfjalsdf"/>
  </form>
</div>
<p style="display:none;">I'm hidden...</p>

<script>
function doIt() {
  $("span,div").show("slow");
}
/* can pass in function name */
$("button").click(doIt);

$("form").submit(function () {
  if ($("input").val() == "yes") {
    $("p").show(4000, function () {
      $(this).text("Ok, DONE! (now showing)");
    });
  }
  $("span,div").hide("fast");
  /* to stop the submit */
  return false;
});
</script>

</body>
</html>

Demo:

Support and Contributions

Need help with .show() or have a question about it? Visit the jQuery Forum or the #jquery channel on irc.freenode.net.

Think you've discovered a jQuery bug related to .show()? Report it to the jQuery core team.

Found a problem with this documentation? Report it on the GitHub issue tracker

  • Marcjon L.

    How do you show items with a display property set to something other than block?

    • http://twitter.com/insekticid insekticid

      $(“#code”).show();

      if ( $(“#code”).is(“tr”) ) {$(“#code”).css(“display”, “”);}//jq 1.4 -> show produces display:block

      • b_rad

        Can someone explain this code?

  • suyog

    hey is dere any other paramenters i have seen a show() with 4 parameters.

    • http://profiles.yahoo.com/u/RRKP7PJQ2IDVQVTWZDRG23IDNM Jatazoulja

      I think the show() with 4 parameters is from jquery ui…

  • Anonymous

    What would be your suggestion to check if some element is shown/hidden? I’ve tryied .css(“display”) without sucess

    • http://www.learningjquery.com/ Karl Swedberg
    • http://www.webit.be/ Jaak Hermans

      AddClass(‘open’) or AddClass(‘hidden’);
      then check which class the container has and replace the classname after you have executed .hide() or .show();

      like:
      $(‘#container’).click(function(){
      if($(‘#subcontainer’).hasClass(‘open’){
      $(‘#subcontainer’).hide();
      $(‘#subcontainer’).removeClass(‘open’);
      $(‘#subcontainer’).addClass(‘hidden’);
      }else{
      …. like above …
      }
      });

    • Jason Shimkoski

      I’d wrap it in an if…

      if ( $(this).is(“:visible”) ) {
      // … do stuff
      }

      • Jason Shimkoski

        Or…

        if ( $(this).is(“:hidden”) ) {
        // … do stuff
        }

    • Reno

      Show if hidden, hide if shown:

      function showOrHide()
      {
      if ($('#id_element').css('display') == “none”)
      $('#id_element').show();
      else
      $('#id_element').hide();
      }

  • JamesHat

    it would be great if you added optional parameters like height only, or width only. right now the default behavior expands both the height and width which can cause some very odd effects with blocks of text.

    • http://twitter.com/pkruithof Peter Kruithof

      I second this. Sometimes I have a table-like design (key-value rows) which I layout using floats/widths. When this is the case hide() looks nice, but show() applies a height attribute during the animation, which is removed at the end, causing the contents of the animated container to move a bit.

      Although this is not the exact same issue, it is something that needs looking into imho.

    • http://www.learningjquery.com/ Karl Swedberg

      You should be using the .animate() method then. Or, if you just want to animate the height, use slideDown/slideUp/slideToggle.

    • http://www.learningjquery.com/ Karl Swedberg

      You should be using the .animate() method then. Or, if you just want to animate the height, use slideDown/slideUp/slideToggle.

  • http://www.google.com/profiles/cmcculloh Christopher McCulloh

    In the final example, the “normal” speed is used. However, in the jQuery source code(http://github.com/jquery/jquery/blob/master/src/effects.js), there is no “normal” speed. Only “slow”, “fast” and “_default”:

    speeds: {
    slow: 600,
    fast: 200,
    // Default speed
    _default: 400
    },

  • Tara_irvine

    I have these div's dynamically generated some with the same class name as it depends on the tag of a post, what I really need is when you show $(“div.CLASS”).show(); to only show 1 if there are more than one divs with that class. They are all in the same parent div so I have no other way of differentiating them. Any help would be amazing!
    Tara xo

  • nicky

    does anyone know the code to allow the selection of specific div tags most people just go straigt for one tag but it effects every thing on screen. At the moment this code just collapses my menu and doesn't even call forth the 4 boxes.

  • Taktka2009
  • Fgg

    thaaaaaaaaaaaaaaaaaaaaaaaank

  • Nuves Rojas

    Its curios but the second example (Hello 3,how are you?) does NOT work in FF 3.6. It's that possible??

  • Kamil

    If I use show(“slow”) in 1.4.2. jQuery… it is working… the same example doesn't work in 1.4.4 … why? what about back compatibility? help please, kamil@axe-design.cz

  • John Doe

    Please note that .show() (as well as .hide()) without parameters does not queue up in the effects queue. To achieve that, you will have to manually queue .show():

    $(“#div”).queue(function(next) {
    $(this).show();
    next();
    });

    To avoid this, it would be helpful to have a queuing version of .show() and .hide(), for example as .show(true).

    PS: .show(1) would be queuing, but still renders a very short animation which is not suitable for applications where absolutely no animation is required.

  • John Doe

    Please note that .show() (as well as .hide()) without parameters does not queue up in the effects queue. To achieve that, you will have to manually queue .show():

    $(“#div”).queue(function(next) {
    $(this).show();
    next();
    });

    To avoid this, it would be helpful to have a queuing version of .show() and .hide(), for example as .show(true).

    PS: .show(1) would be queuing, but still renders a very short animation which is not suitable for applications where absolutely no animation is required.

  • b_rad

    Can someone explain this code?

  • Ss

    not so helpful

  • Ramico

    i want to show() a table display

    • Ramico

      i meant show() and all other animating effics make the element/s in the selection set display = to block eventually i have a pre that should be displayed or shall i say toggle display from none to table

      in other words
      pre{display:none}

      $('pre').show() //should make the pre display table

  • Doanthich

    Thank's you!
    here: the website: http://vietnamtravel-destinati… .I used, i think Success!

  • vespadj

    ops… it was my fist post.
    //Usage:
    create an A elem <–a style=”cursor: pointer” onclick=”javascript:$(this).next('div').hideShow();” ><–u>notes<–/u->

    delete “–”

  • Thiyagarajan Veluchamy

    Thanks