I want to开发者_Go百科 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:
- Entire struct is displayed
- 1.1
- 1.1.1
- 1.2
- 1.1
- Only this li is shown
EDIT: added children to jQuery, but still not working as desired.
The following worked for me..
$("ul").find("ul").hide();
$("ul > li.current").find("ul").show().end().parents().show();
http://jsfiddle.net/uHyPS/5/
精彩评论