Skip to content

Instantly share code, notes, and snippets.

@amityweb
Created June 29, 2020 08:51
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 amityweb/8c32496cb4a837bb618f07a2ea6a46f3 to your computer and use it in GitHub Desktop.
Save amityweb/8c32496cb4a837bb618f07a2ea6a46f3 to your computer and use it in GitHub Desktop.
/* HTML/PHP */
<div class="accordion">
<?php foreach($accordions AS $accordion) : ?>
<div class="accordion-row col sixcol">
<a href="#" class="accordion-title"><?php echo $accordion['question'];?></a>
<div class="accordion-text"><?php echo $accordion['answer'];?></div>
</div>
<?php endforeach;?>
</div>
/* CSS */
.accordion
{
overflow: visible;
}
.accordion-row
{
position: relative;
}
.accordion-title
{
padding: 10px 0;
}
.accordion-text
{
display: none;
}
/* JQuery */
$(document).ready(function()
{
if($('.accordion').length > 0)
{
$(".accordion-title").click(function(e)
{
e.preventDefault();
$('.accordion-text').slideUp('fast');
if( !$(this).hasClass('open') )
{
$(this).addClass('open').next('.accordion-text').slideDown('fast');
}
else
{
$('.accordion-title').removeClass('open');
$('.accordion-text').slideUp('fast');
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment