I am looking for some help with collapsible I am trying to change the icon on the headers when they are active but cant seem to solve the problem of if I click on another header without closing the first one having the proper icon being displayed.
Here is a codepen with an example of my issue. http://codepen.io/FPC/pen/xZEWVY
here is my code:
<div class="container">
<div class="row">
<div class="col s6">
<ul class="collapsible popout" data-collapsible="accordion">
<li>
<div class="collapsible-header">
<i class="material-icons right more">expand_more</i>
<i class="material-icons right less" style="display: none">expand_less</i>
Article Title
</div>
<div class="collapsible-body">
<p>
Content Snipit
</p>
</div>
</li>
<li>
<div class="collapsible-header">
<i class="material-icons right more">expand_more</i>
<i class="material-icons right less" style="display: none">expand_less</i>
Article Title
</div>
<div class="collapsible-body">
<p>
Content Snipit
</p>
</div>
</li>
<li>
<div class="collapsible-header">
<i class="material-icons right more">expand_more</i>
<i class="material-icons right less" style="display: none">expand_less</i>
Article Title
</div>
<div class="collapsible-body">
<p>
Content Snipit
</p>
</div>
</li>
</ul>
</div>
</div>
</div>
here is the JS I am using
$(document).ready(function(){
$( ".collapsible-header" ).click(function() {
$(".more",this).toggle()
$(".less", this).toggle()
});
});
You don't need the use javascript for this
<ul class="collapsible" data-collapsible="accordion">
<li>
<div class="collapsible-header">
<i class="material-icons">expand_less</i>First</div>
</li>
<li>
<div class="collapsible-header">
<i class="material-icons">expand_less</i>Second</div>
</li>
</ul>
.collapsible li.active i {
-ms-transform: rotate(180deg); /* IE 9 */
-webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
transform: rotate(180deg);
}
As an addition to Hakan's answer, You can use the collapsible-header
class to avoid changing other icons within the collapsible class (accordion content). The CSS code that worked for me is:
CSS
.collapsible-header.active i {
-ms-transform: rotate(180deg); /* IE 9 */
-webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
transform: rotate(180deg);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With