You may have seen my pure CSS accordion control, well here is a JQuery version that I much rather. The only external resource is Google's font CDN(href here).
HTML:
HTML Code:
<section class="accordion">
<header class="accordionHeader">
<h2>Title</h2>
<i class="material-icons">expand_more</i>
<i class="material-icons">expand_less</i>
</header>
<section>
</section>
</section>
<section class="accordion">
<header class="accordionHeader">
<h2>Title</h2>
<i class="material-icons">expand_more</i>
<i class="material-icons">expand_less</i>
</header>
<section>
</section>
</section>
CSS
Code:
.accordionHeader {
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-justify-content: flex-start;
-ms-flex-pack: start;
justify-content: flex-start;
-webkit-align-content: stretch;
-ms-flex-line-pack: stretch;
align-content: stretch;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
border-bottom: 1px solid #666;
}
.accordionHeader h2 {
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
-webkit-align-self: auto;
-ms-flex-item-align: auto;
align-self: auto;
}
.accordionHeader i {
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 0 1 auto;
-ms-flex: 0 1 auto;
flex: 0 1 auto;
-webkit-align-self: auto;
-ms-flex-item-align: auto;
align-self: auto;
cursor: pointer;
border: 2px solid #666;
border-radius: 50%;
}
JQuery:
Code:
$(function() {
$('.accordionHeader i:last-child').hide();
$('.accordion').children('section').hide();
$('.accordionHeader i').on('click', function() {
$(this).parent().children('i').toggle();
$(this).parent().next('section').toggle();
});
});
Fiddle: http://codepen.io/anon/pen/WrWbzR