Agyan
adda
Run
Reset
Copy
jQuery Tutorial › jQuery Slide › FAQ accordion with slideToggle
Back to tutorial
Code
Edit, then press Run or Ctrl+Enter
<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>
Result