I have simple vertical menu using list elements like below
<ul id="leftNav">
<li id="home"><a href="/index.html">Home</a>
</li>
<li id="apples"><a href="/category/apples.html">Apples</a>
<ul class="subMenu">
<li><a href="/category/red-apples.html">Red Apples</a>
</li>
<li><a href="/category/green-apples.html">Green Apples</a>
</li>
<li><a href="/category/golden-apples.html">Golden Apples</a>
</li>
</ul>
</li>
<li id="grapes"><a href="/category/grapes.html">Grapes</a>
<ul class="subMenu">
<li><a href="/category/red-grapes.html">Red Grapes</a>
</li>
<li><a href="/category/green-grapes.html">Green Grapes</a>
</li>
<li><a href="/category/black-grapes.html">Black Grapes</a>
</li>
</ul>
</li>
<li id="dry-fruits"><a href="/category/dry-fruits.html">Dry Fruits</a>
<ul class="subMenu">
<li id="subParent1"><a href="#">Fruits That Are Dried</a>
<ul class="subMenu1">
<li><a href="/category/figs.html">Figs</a>
</li>
<li><a href="/category/dates.html">Dates</a>
</li>
<li><a href="/category/pineapples.html">Pine Apples</a>
</li>
</ul>
</li>
<li id="subParent2"><a href="#">Nuts and Seeds</a>
<ul class="subMenu1">
<li><a href="/category/chestnuts.html">Chestnuts</a>
</li>
<li><a href="/category/almonds.html">Almonds</a>
</li>
<li><a href="/category/walnuts.html">Walnuts</a>
</li>
</ul>
</li>
<li id="subParent3"><a href="/category/bananas.html">Bananas</a>
</li>
</ul>
</li>
<li id="sale" class="expanded"><a href="/category/sale.html">Sale</a>
</ul>
What I am trying to do is when apples or its sub items are clicked I am trying keep that sections of the list expanded and so on, so when Grapes or its sub items are clicked all other should be closed except Grapes section.
I tried using code like below, but since Apples and Grapes are links which render their respective pages, my code below is not working.
$(document).ready(function() {
$("#apples .subMenu").css("display", "block");
});
Any help or example or advice is appreciated.