Last active
May 17, 2018 14:55
-
-
Save arterzatij/fecde3e01f345959c7baf247080dbcb5 to your computer and use it in GitHub Desktop.
Accordion Code Assessment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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