agyanadda@gmail.com

jQuery Slide

jQuery Effects 1 min read Updated Dec 1, 2026 Topic 8 of 25

Slide effects animate an element's height.

  • .slideDown() — slide a hidden element open
  • .slideUp() — slide it closed
  • .slideToggle() — open or close

Speed and callback work like other effects.

FAQ accordion idea

  1. Hide all answers at the start
  2. When a question is clicked, slideToggle() its answer
  3. Close the other answers with slideUp()
$('.question').click(function () {
  $(this).next('.answer').slideToggle();
  $('.answer').not($(this).next()).slideUp();
});

.next() finds the element right after the clicked question.

Example

Example — FAQ accordion with slideToggle HTML
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<style>
  .question { background:#1f386b; color:#fff; padding:10px; margin-top:6px; cursor:pointer; border-radius:4px; }
  .answer { display:none; padding:10px; border:1px solid #ddd; border-top:none; }
</style>

<div class="question">Are AgyanAdda tutorials free?</div>
<div class="answer">Yes, every tutorial is free to read.</div>
<div class="question">Can I run the examples?</div>
<div class="answer">Yes, click "Try it Now" under any example.</div>
<div class="question">Do you have live classes?</div>
<div class="answer">Yes, see the Online Training page.</div>

<script>
  $(function () {
    $('.question').click(function () {
      const $answer = $(this).next('.answer');
      $('.answer').not($answer).slideUp();
      $answer.slideToggle();
    });
  });
</script>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which method opens or closes an element with a sliding effect?

Exercise 2 True / False

Slide effects animate the height of an element.

Exercise 3 Fill in the Blank

$(this).___() selects the element right after the current one.

Frequently Asked Questions

Padding or margin on the element can cause jumps. Put the padding on an inner element and slide the outer wrapper.