Reputation: 14406
I want to display the entire ul li struct that has a class current
somewhere in it
Every other ul li I want to hide. EXCEPT The top level.
My jQuery is not doing what I want, any suggestions?
$("ul li").find("ul").hide();
$("ul:has(li.current)").parents().show();
$("ul:has(li.current)").children().show();
For example:
<ul>
<li>Entire struct is displayed
<ul>
<li>1.1
<ul>
<li class="current">1.1.1</li>
</ul>
</li>
<li>1.2</li>
</ul>
</li>
<li>Only this li is shown
<ul>
<li>2.1</li>
<li>2.2</li>
</ul>
</li>
</ul>
Displays as:
EDIT: added children to jQuery, but still not working as desired.
Upvotes: 1
Views: 748
Reputation: 82325
The following worked for me..
$("ul").find("ul").hide();
$("ul > li.current").find("ul").show().end().parents().show();
Upvotes: 2