AD JB Toolbox 01 EN

jQuery .slideDown(): Expand and Show Hidden Content

.slideDown() animates an element’s vertical size to show its content. It does not remove the element from the document, so the opposite effect can reverse its visibility.

Syntax and behavior

$("#panel").slideDown(400, "swing", function () {
  // Run after this element finishes animating.
});
$("#panel").slideDown({ duration: 400, easing: "linear" });

duration is the running time in milliseconds, with a default of 400. "fast" means 200 milliseconds and "slow" means 600; larger values produce longer animations. easing controls how the speed changes: swing is the default variable-speed curve, while linear progresses at a constant rate. A complete callback runs once per element after its animation finishes, with this set to that DOM element. The method returns a jQuery object immediately, so returning does not indicate that the animation has finished. The complete example uses display: none for the initially hidden panel. A hidden attribute or an additional forced-hiding rule can interfere with showing it.

The official jQuery .slideDown() documentation describes additional call signatures and argument types.

Complete runnable example

Save the following code as a UTF-8 example.html file and open it in a browser. It loads the full jQuery 4.0.0 build from an external URL, so an internet connection is required. The $(function () { ... }) callback waits for the document to be ready before running the example.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery slideDown example</title>
  <style>
    body { margin: 24px; font-family: sans-serif; line-height: 1.6; }
    .marked { background: #fff0b3; border: 2px solid #835b00; }
    .active { color: #a00000; font-weight: bold; }
    button, input, select { font: inherit; }
    #output { white-space: pre-wrap; overflow-wrap: anywhere; }
  </style>
  <script src="https://code.jquery.com/jquery-4.0.0.min.js"></script>
</head>
<body>
<button id="run" type="button" aria-controls="panel" aria-expanded="false">Expand</button>
<button id="reset" type="button">Reset</button>
<div id="panel" class="marked" style="display: none;"><p>This is the collapsible help content.</p></div>
  <p id="output" aria-live="polite"></p>
  <script>
    $(function () {
      $("#run").on("click", function () {
        const $button = $(this);
        const duration = window.matchMedia("(prefers-reduced-motion: reduce)").matches ? 0 : 400;
        $("#panel").stop(true, true).slideDown(duration, "swing", function () {
          const visible = $(this).is(":visible");
          $button.attr("aria-expanded", String(visible));
          $("#output").text(visible ? "Expanded" : "Collapsed");
        });
      });
      $("#reset").on("click", function () {
        $("#panel").stop(true, true).hide();
        $("#run").attr("aria-expanded", "false");
        $("#output").text("Initial state");
      });
    });
  </script>
</body>
</html>

Expected result

The panel starts hidden. Clicking Expand reveals it and displays Expanded. Reset clears the active effect and restores the initial visibility. When the operating system requests reduced motion, this example uses a duration of zero for an immediate state change.

Waiting for all selected animations

$(".panel").slideDown(400).promise().done(function () {
  console.log("All panel animations finished");
});

Use this snippet with several elements whose class is panel. .promise() waits for the default fx queue and separates collection-wide completion from the per-element complete callback.

Important details and troubleshooting

  • The slim build excludes effects, so these methods require a build that includes the effects module. Use the full build shown in the example and check script loading in the browser’s Network panel.
  • Effects normally enter an element’s fx queue. .stop(true, true) clears pending effects and jumps the current effect to its end before starting another. Jumping to the end can also run the previous completion callback.
  • For multiple elements, complete runs once for each element. Use .promise().done() when a single action should run after the whole collection’s effects finish.
  • If keyboard focus is inside a panel about to be hidden, consider moving it to a visible control first. The animation alone does not manage focus or accessibility state.
  • A child will remain invisible if an ancestor is hidden. Check ancestor display, !important rules, empty content, and height constraints when nothing appears.

See the .stop() documentation for queue handling, the .promise() documentation for collection-wide completion, and the jQuery full and slim build descriptions for module availability.

Compare the behavior with .slideUp() for collapsing content, .slideToggle() for switching visibility.

More in This Category
jQuery .slideDown(): Expand and Show Hidden Content

jQuery .slideDown(): Expand and Show Hidden Content

Reveal a hidden panel and handle its initial state, animation queue, callbacks, reset behavior, and reduced motion.

jQuery :contains(): Match Elements by Text Content

jQuery :contains(): Match Elements by Text Content

Explore case-sensitive substring matching, descendant text, and a safer way to handle dynamic search strings without constructing selectors.

jQuery .addBack(): Include the Previous Traversal Selection

jQuery .addBack(): Include the Previous Traversal Selection

Include the previous traversal collection and understand which elements the optional selector filters.

jQuery .slideUp(): Collapse and Hide Content

jQuery .slideUp(): Collapse and Hide Content

Collapse a panel with duration, easing, and completion handling, including queued effects, reset behavior, and reduced motion.

jQuery .removeAttr(): Delete HTML Attributes

jQuery .removeAttr(): Delete HTML Attributes

Compare deleting an attribute with setting an empty value, and handle input values, current properties, and ARIA attributes correctly.

jQuery .has(): Select Elements with Matching Descendants

jQuery .has(): Select Elements with Matching Descendants

Filter the original selection by matching descendants, and see why has and find return different elements.

jQuery :button Selector: Which Elements Does It Match?

jQuery :button Selector: Which Elements Does It Match?

Check how :button treats button elements, ordinary button inputs, and submit or reset inputs, with a working selection example.

jQuery .find(): Select Matching Descendants

jQuery .find(): Select Matching Descendants

Search through descendant levels while excluding the container, and compare find with children, filter, and has.

jQuery .appendTo(): Insert Content as the Last Child

jQuery .appendTo(): Insert Content as the Last Child

Start with the content to insert it at a destination’s end, and inspect the returned selection and moving or cloning behavior.

jQuery .empty(): Clear Content and Keep the Container

jQuery .empty(): Clear Content and Keep the Container

Clear a container’s elements and text without deleting it, refill it, and understand how field values and event handlers differ.