multiple UL and LI to traverse
Hi,
i have something like that as menu:
- <div id='main_div'>
<ul class='ul_main current'>
<li class='level1 item1'>item 1</li>
<li class='level1 item2 current'>item 2
<ul>
<li class='level2 item1'>item 2.1</li>
<li class='level2 item2 current'>item 2.2</li>
</ul>
</li>
<li class='level1 item3'>item 3
<ul>
<li class='level2 item1'>item 3.1</li>
<li class='level2 item2'>item 3.2</li>
</ul>
</li>
<li class='level1 item4'>item4</li>
</ul>
</div>
the item selected will always have a class 'current'
every LI or UL which doesn't have current has class should be hidden.
i tried to use the hasChildren and each functions for that but without success has it takes only the first UL has child. But it doesn't check children of UL and all subitems.
- $("#main_div").children().each(function(i,e)
{
if($(this).hasClass('current'))
{
$(this).show();
}
else
{
$(this).hide();
}
});
do you have any idea how to do it easily ?
thanks a lot,
A.