Skip to content

Instantly share code, notes, and snippets.

@rahuladams
Last active June 19, 2020 12:33
Show Gist options
  • Save rahuladams/58c4be260d55d31eb813c3a8109a3768 to your computer and use it in GitHub Desktop.
Save rahuladams/58c4be260d55d31eb813c3a8109a3768 to your computer and use it in GitHub Desktop.
var accordion_items = document.querySelectorAll('.accordion-item');
if (accordion_items != null) {
var i = 0;
accordion_items.forEach(function (e) {
i++;
e.addEventListener('click', function () {
e.querySelector('.accordion-content').classList.toggle('active');
});
})
}
//HTML
<div class="accordion-item">
<div class="accordion-heading medium-b-pad">HEADING</div>
<div class="accordion-content">CONTET_TO_REVEAL</div>
</div>
//SCSS
.accordion{
&-item{
margin-bottom: 30px;
border-bottom: 1px solid #000;
}
&-heading{
cursor: pointer;
&:hover{
opacity: .8;
}
}
&-content{
display: none;
&.active{
display: block;
padding-bottom: 30px;
}
}
h6{
margin-bottom: 20px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment