开发者

jQuery parent <li>

开发者 https://www.devze.com 2023-01-15 12:37 出处:网络
<ul class=\"menu\"> <li><a href=\"#\">texT</a> <ul> <li>text</li>
<ul class="menu">
<li><a href="#">texT</a>
    <ul>
        <li>text</li>
        <li>text</li>
        <li>text</li>
    </ul>
</li>
<li>text</li>
<li>text</li>
</ul>

How t开发者_如何转开发o get direct <li> from .menu?

<li> inside child <ul> should not be taken.

Thanks.


You can use the child selector:

$('.menu > li')

I recommend taking a look at jQuery's selector documentation.


You could try the .children() function:

var lis = ​$('.menu')​.children('li')​;


$(".menu > li")


would this work?

$(".menu > li")
0

精彩评论

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