开发者

Add Classes to first level list tags

开发者 https://www.devze.com 2022-12-18 10:41 出处:网络
is there a way to add class to only one level on li tags? in m case at the moment it looks like this:

is there a way to add class to only one level on li tags? in m case at the moment it looks like this:

<ul>
    <li></li>
    <li>
        <ul>
            <li></li>
            <li></li>
        </ul>
    </li>开发者_Go百科;
    <li></li>
</ul>
And this is what I need
<ul>
    <li class="lev-one"></li>
    <li class="lev-one">
        <ul>
            <li></li>
            <li></li>
        </ul>
    </li>
    <li class="lev-one"></li>
</ul>

Thank you for your help in advance.

Dom


Try this:

$("*:not(li) > ul > li").addClass("lev-one")
0

精彩评论

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