I am using font awesome to put arrows on an accordion sidebar menu. The extra {liquid code}
is from Shopify. I am having a problem to properly toggle my <i class="">
since the class can depend on if the link is active or not.
I am trying to have only the active or open <i>
to be fa-angle-up and the others fa-angle-down.
HTML
<div id="accordian">
<ul>{% for link in linklists.shop.links %}
<li class="{% if link.active %}active{% endif %}">
<h3>{{ link.title | escape }}
<span><i class={% if link.active %}"fa fa-angle-up" aria-hidden="true"{% else %}"fa fa-angle-down" aria-hidden="true"{% endif %}></i></span>
</h3>
</li>
</ul>
</div>
JQUERY
$(document).ready(function(){
$("#accordian h3").click(function(){
$(this).find('i').toggleClass('fa-angle-down fa-angle-up');
$("#accordian ul ul").slideUp();
if(!$(this).next().is(":visible"))
{
$(this).next().slideDown();
}
})
});
2
Answers
i guess you want something like this. it’s not the cleanest solution but it works as you want ( as i understood your question )
I added an example here similar to what you want. It disables other
li
once you click on any other.you can remove that functionality by removing first two lines of the click event function
I also altered some html for better snippet run. you can replace it easily.