开发者

jQuery - first line of li elements in ul

Is there a selector in jQuery which refers to only first line of specific children of the main object? What I'm referring here to is the following structure:

<ul>
    <li>
        <ul>
            <li></li>
        </ul>
    </li>
    <li>
        <ul>
   开发者_StackOverflow社区         <li></li>
        </ul>
    </li>
</ul>

I only want apply a trigger to the first line of li not the ones embedded within them.


<ul class="top">
    <li>
        <ul>
            <li></li>
        </ul>
    </li>
    <li>
        <ul>
            <li></li>
        </ul>
    </li>
</ul>


$("ul.top>li")

That means only direct child li nodes of the ul

Otherwise if you don't have control of the classes you can use

$("ul:first>li")


$("ul:first > li").something(); //<--


The following code will fetch only the li elements that are children of ul not li

    $('ul').children('li');

in your code I suppose it ll be something like

    $('ul li').click(function(){
        if($(this).parents('li')) {      //add extra check
             return;                    //do nothing
        }

    })

This is only to give a hint

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜