jQuery选择器|复杂选择

时间:2010-10-18 11:36:03

标签: jquery jquery-selectors

我有一个这样的清单:

<div class="cloned"><a rel="test" href="" title=""></a></div>
<div><a rel="test" href="" title=""></a></div>
<div><a rel="test" href="" title=""></a></div>
<div><a rel="test" href="" title=""></a></div>
<div class="cloned"><a rel="test" href="" title=""></a></div>

我想使用jQuery选择所有<a>rel=test,但不包括div类克隆的所有<a>。像这样的东西

$("div:not(.cloned) a[rel=test]")

谢谢

1 个答案:

答案 0 :(得分:7)

你的确有什么工作:

$("div:not(.cloned) a[rel=test]")

You can test it here,如果您遇到问题,请确保您在document.ready处理程序中,如下所示:

$(function() {
  $("div:not(.cloned) a[rel=test]").css('color', 'red');​
});
相关问题