Skip to content

Instantly share code, notes, and snippets.

@BulatSa
Last active July 18, 2018 11:17
Show Gist options
  • Save BulatSa/a77fe9b536f1d00c001775bab58952c6 to your computer and use it in GitHub Desktop.
Save BulatSa/a77fe9b536f1d00c001775bab58952c6 to your computer and use it in GitHub Desktop.
FAQ Opening on title
<div class="faq__list">
<div class="faq__item open">
<div class="faq__item-title">
<div class="faq__item-quest">
<p>Question</p>
</div>
</div>
<div class="faq__item-answer user-content">
<p>Answer</p>
</div>
</div>
</div>
/***********************
Faq BEGIN
***********************/
$(document).ready(function() {
if($('.faq__item-title').length) {
$('.faq__item-answer').slideUp();
$('.faq__item.open').find('.faq__item-answer').slideToggle();
$('.faq__item-title').on('click', function(){
var $this = $(this);
var $faqList = $this.parents('.faq__list');
var $otherItems = $faqList.find('.faq__item-title').not($this).closest('.faq__item');
$otherItems.removeClass('open');
$otherItems.find('.faq__item-text').slideUp();
$this.next('.faq__item-text').slideToggle();
$this.closest('.faq__item').toggleClass('open');
});
}
});
/***********************
Faq END
***********************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment