Skip to content

Instantly share code, notes, and snippets.

@arterzatij
Last active May 17, 2018 14:55
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 arterzatij/fecde3e01f345959c7baf247080dbcb5 to your computer and use it in GitHub Desktop.
Save arterzatij/fecde3e01f345959c7baf247080dbcb5 to your computer and use it in GitHub Desktop.
Accordion Code Assessment
<style>
li {
list-style-type: none;
}
h3 {
cursor: pointer;
}
div {
overflow: hidden;
max-heigth: 50px;
background: red;
}
.collapsed {
display: none;
}
</style>
<ul>
<li><h3>LOrem 1</h3><div><p>text</p></div></li>
<li><h3>LOrem 1</h3><div><p>text</p></div></li>
<li><h3>LOrem 1</h3><div><p>text</p></div></li>
<li><h3>LOrem 1</h3><div><p>text</p></div></li>
</lu>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
(function($titles, $contents, collapsedClass) {
$titles.on('click', function(event) {
$contents.addClass(collapsedClass);
$(event.target).siblings('div').removeClass(collapsedClass);
});
$contents.addClass(collapsedClass).first().removeClass(collapsedClass)
})($('h3'), $('div'), 'collapsed');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment