0

如果我有以下 html,我如何使用 Jquery 仅选择第一级子级并应用 :not to them

<div id="top">
    <span>select me</span>
    <a>select me</a>
    <div>
        <span>not this</span>
        <a>not this</a>
    </div>
    <div class="not-this">not this</div>
</div>

jQuery:

jQuery('#top>:not(.not-this)'); // errors due to the >
jQuery('#top:not(.not-this)');  // selects the second level children.

它需要与用于孩子的标签无关。

编辑添加:也尝试过

jQuery('#top>*:not(.not-this)');  // selects the second level children.
4

1 回答 1

2

jQuery('#top>:not(.not-this)')实际上应该可以正常工作。 http://jsfiddle.net/Entxc/

另一种选择是:

$("#top").children().not(".not-this")

http://jsfiddle.net/Entxc/1/

于 2013-03-21T15:24:00.157 回答