我有使用如下列表元素的简单垂直菜单
<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>
我想要做的是当点击苹果或其子项目时,我试图保持列表的这些部分展开等等,所以当点击葡萄或其子项目时,除了葡萄部分之外,所有其他都应该关闭。
我尝试使用下面的代码,但由于 Apples 和 Grapes 是呈现各自页面的链接,所以下面的代码不起作用。
$(document).ready(function() {
$("#apples .subMenu").css("display", "block");
});
任何帮助或示例或建议表示赞赏。