开发者

jquery selector for child element

开发者 https://www.devze.com 2023-01-17 13:40 出处:网络
What is the correct method for looping through the lowest level \"li\" elements? <div id=\"mainnav\">

What is the correct method for looping through the lowest level "li" elements?

<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 -->
        开发者_StackOverflow社区    </ul>
        </li>
    </ul>
</div>

I've tried this but the selector is not firing.

jQuery("#mainNav > ul > li > ul > li").each(function () { 

});


#ID selectors are case sensitive, you need #mainnav (lower case n), like this:

jQuery("#mainnav > ul > li > ul > li").each(function () { 

});

You can test it out here.

0

精彩评论

暂无评论...
验证码 换一张
取 消