我有三个无序列表互相嵌套。第二个和第三个ul
被隐藏(display: none;
)
首先,我需要显示ul.second
的{{1}}的所有li
元素。
根据第二个事件,我需要显示ul.first
ul.third
的所有li
元素。
这是代码:
HTML
ul.second
CSS
<ul class="first">
<li class="first-element">
<ul class="second">
<li class="second-element">
<ul class="third">
<li class="third-element"></li>
<li class="third-element"></li>
<li class="third-element"></li>
</ul>
</li>
<li class="second-element">
<ul class="third">
<li class="third-element"></li>
<li class="third-element"></li>
<li class="third-element"></li>
</ul>
</li>
<li class="second-element">
<ul class="third">
<li class="third-element"></li>
<li class="third-element"></li>
<li class="third-element"></li>
</ul>
</li>
</ul>
</li>
<li class="first-element">
<ul class="second">
<li class="second-element">
<ul class="third">
<li class="third-element"></li>
<li class="third-element"></li>
<li class="third-element"></li>
</ul>
</li>
<li class="second-element">
<ul class="third">
<li class="third-element"></li>
<li class="third-element"></li>
<li class="third-element"></li>
</ul>
</li>
<li class="second-element">
<ul class="third">
<li class="third-element"></li>
<li class="third-element"></li>
<li class="third-element"></li>
</ul>
</li>
</ul>
</li>
</ul>
JS
ul.second li {
display: none;
}
ul.third li {
display: none;
}
如何以其他方式定位$('li.first-element:eq(0) li.second-element').show(); // works fine, it shows only li.second-element of ul.first first li
$('li.second-element:eq(0) li.third-element').show(); // does not work, in log it gives me empty []
?
答案 0 :(得分:0)
然后
$('.first li:eq(0) .second > li');
$('.second > li:eq(0) .third > li');