Skip to content

Instantly share code, notes, and snippets.

@SashaKolbasov
Last active May 16, 2018 14:49
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 SashaKolbasov/acad01d2808aa8f7bb79426c86e352a4 to your computer and use it in GitHub Desktop.
Save SashaKolbasov/acad01d2808aa8f7bb79426c86e352a4 to your computer and use it in GitHub Desktop.
Easy Accordion.
// js-acc
var accItems = $('.js-acc > .item');
var accTitles = $('.js-acc > .item > .title');
accItems.removeClass('open').find('.desc').slideUp();
accItems.eq(0).addClass('open').find('.desc').slideDown();
accTitles.on('click', function() {
var parent = $(this).parent('.item');
if (parent.hasClass('open')) {
parent.removeClass('open').find('.desc').slideUp();
} else {
accItems.removeClass('open').find('.desc').slideUp();
parent.addClass('open').find('.desc').slideDown();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment