如果我有以下的HTML,我怎么使用jQuery,只选择第一级子和适用:不给他们如何选择的所有直接子:没有()
<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.
你用'>'得到什么的jQuery的版本,什么 “错误”?你声称的结果没有一个应该像你说的那样工作。 – 2013-03-21 15:26:16
@JamesMontagne我刚刚重试,并没有错误,但它仍然没有做我想做的。 – SystemicPlural 2013-03-21 15:31:51