Hide Submenu by Default, Show if Active

655 Views Asked by At

http://jsfiddle.net/L9wrt41g/

Working with the Sidr menu.

By default submenus are hidden.

.sidr ul.submenu {
display:none;
}

But as you can see in the fiddle, Sub List 2 has an active class.

<li class="active"><a href="#">Sub List 2</a></li>

Trying to figure out how to have the parent submenu visible by default if one of its children have an active class.

Therefore (since a submenu item has an active class), upon page load (and after clicking 'Toggle Menu') it should be visible by default, as such:

https://s23.postimg.org/uealsexqj/sidr.png

1

There are 1 best solutions below

1
On BEST ANSWER

Sorry for the Wrong answer. Here you go

you should add this to your document ready function.

$("li.active").each(function (i,e) {
    $(e).parent().css("display","block");
});