Skip to content

Instantly share code, notes, and snippets.

@moladukes
Created February 22, 2018 18:14
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 moladukes/77d89b31ebe3940bac335ce9d1ba741b to your computer and use it in GitHub Desktop.
Save moladukes/77d89b31ebe3940bac335ce9d1ba741b to your computer and use it in GitHub Desktop.
Simple jQuery Accordion Snippet
<!-- Demo https://codepen.io/moladukes/pen/jZKRrJ -->
<ul>
<li><a href="#" class="accordian-toggle">Toggle</a>
<li class="accordian-description">Description</li>
<li><a href="#" class="accordian-toggle">Toggle</a>
<li class="accordian-description">Description</li>
<li><a href="#" class="accordian-toggle">Toggle</a>
<li class="accordian-description">Description</li>
</ul>
<script>
var d = $('.accordian-description').hide();
var l = $('.accordian-toggle');
$(l).click(function(e){
e.preventDefault();
var t = $(this);
if (t.hasClass('active')) {
t.removeClass('active');
t.parent().next().hide();
} else {
d.hide();
l.removeClass('active');
t.addClass('active');
t.parent().next().show();
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment