循环使用最低级别“li”元素的正确方法是什么?
<div id="mainnav">
<ul>
<li>
<ul>
<!-- These are the elements I want to loop through -->
<li>
</li>
<li>
</li>
<li>
</li>
<!-- End These are the elements I want to loop through -->
</ul>
</li>
</ul>
</div>
我试过了,但选择器没有开火。
jQuery("#mainNav > ul > li > ul > li").each(function () {
});
答案 0 :(得分:1)
#ID selectors区分大小写,您需要#mainnav
(小写n
),如下所示:
jQuery("#mainnav > ul > li > ul > li").each(function () {
});