如何选择所有带有孩子的可见<li>元素? (jquery选择器)

时间:2015-10-22 17:16:54

标签: jquery html

我的html结构如下:

<li style="display: block;">
    <label>..
    <input>..
    <ol>
        <li style="display: block;">
            <label>..
            <input>..
            <ol>
                <li style="display: none;"> <!--Don't select this-->
                    <label>..
                    <input>..
                    <ol>
                        <li style="display: block;"> <!--Don't select this-->
                            <leaf>..
                        </li>
                    </ol>
                </li>
            </ol>
            <ol>
                <li style="display: block;"> <!--Don't select this-->
                    <leaf>..
                </li>
            </ol>
        </li>
    </ol>
</li>

我想选择所有<li>元素 1)是可见的 2)不是叶节点

我从

开始
$("li:visible").each(function() {...})

但我找不到任何jquery选择器(或css选择器),它排除没有任何子元素的元素。请帮忙。

注意:此问题与建议的重复完全不同。我不打算选择没有孩子的所有元素。另外,我有一个额外的条件(可见)。我的头衔错了,误导了,现在已经修改了。

1 个答案:

答案 0 :(得分:-1)

修正您的html,使<ul>成为<li>的父级,因为它当前无效

然后尝试

$('li:visible:has(ol)').each(function() {...})