Script
var toggle = new Toggle({
buttonClass: 'toggle-btn',
buttonClassExpanded: 'toggle-btn-active',
buttonContent: '<span class="sr-only">Toggle</span><i class="fa fa-angle-down" aria-hidden="true"></i>',
createButtons: true,
parentClass: 'toggle-parent',
targetSelector: '.menu ul ul'
})
HTML
<nav class="menu">
<ul>
<li>
<a href="#">Pie</a>
<ul>
<li><a href="#">Apple Pie</a></li>
<li>
<a href="#">Cherry Pie</a>
<ul>
<li><a href="#">With Pastry Crust</a></li>
<li><a href="#">With Graham Cracker Crust</a></li>
</ul>
</li>
<li><a href="#">Pumpkin Pie</a></li>
<li><a href="#">Chocolate Pie</a></li>
</ul>
</li>
<li>
<a href="#">Cake</a>
<ul>
<li>
<a href="#">Vanilla Cake</a>
<ul>
<li><a href="#">With Vanilla Icing</a></li>
<li><a href="#">With Chocolate Icing</a></li>
<li><a href="#">With Sprinkles</a></li>
</ul>
</li>
<li><a href="#">Chocolate Cake</a></li>
<li><a href="#">Fruit Cake</a></li>
</ul>
</li>
<li><a href="#">Ice Cream</a></li>
</ul>
</nav>
CSS
/* Hide collapsed */
[aria-expanded="false"] {
display: none;
}
/* Position toggle buttons */
.toggle-parent {
position: relative;
}
.toggle-btn {
position: absolute;
right: 0;
top: 0;
}
/* Flip the icon */
.toggle-btn i {
transition: transform 0.3s ease;
}
.toggle-btn-active i {
transform: rotate(180deg);
}