Created
February 22, 2018 18:14
-
-
Save moladukes/77d89b31ebe3940bac335ce9d1ba741b to your computer and use it in GitHub Desktop.
Simple 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
<!-- 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