Created
October 17, 2020 07:28
-
-
Save coder618/1adc6058c3bc58b3e0906065e005d083 to your computer and use it in GitHub Desktop.
jQuery Accordion snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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