Skip to content

Instantly share code, notes, and snippets.

@coder618
Created October 17, 2020 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coder618/1adc6058c3bc58b3e0906065e005d083 to your computer and use it in GitHub Desktop.
Save coder618/1adc6058c3bc58b3e0906065e005d083 to your computer and use it in GitHub Desktop.
jQuery Accordion snippet
<ul class="accordion">
<?php for($i=0; $i< 5; $i++): ?>
<li>
<a class="toggle" href="javascript:void(0);">Item 1 <i class="far fa-chevron-down"></i></a>
<div class="inner">
some inner textttttttt
</div>
</li>
<?php endfor; ?>
</ul>
<script>
$(".toggle").click(function (e) {
e.preventDefault();
var $this = $(this);
$(".accordion li").removeClass("shown");
if ($this.next().hasClass("show")) {
$this.next().removeClass("show");
$this.next().slideUp(350);
} else {
$this.parent().parent().find("li .inner").removeClass("show");
$this.parent().parent().find("li .inner").slideUp(350);
$(this).parents("li").addClass("shown");
$this.next().toggleClass("show");
$this.next().slideToggle(350);
}
});
<script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment