2013-11-03 59 views
0

我需要关于jQuery的帮助,目前我正在使用以下选择器。jQuery选择除一个特定的所有A之外

$("#myDiv>a") 

这将选择我司的所有50个链接,我如何过滤出被选中的特定链接?我的链接href包含“cat -kennel”,我尝试使用(href * -cat-kennel),但它不起作用?

回答

3

您可以使用:not选择器。

$('#myDiv a:not([href*="cat-kennel"])'); 

如果您的过滤逻辑比较复杂,您可以使用filter

$('#myDiv a').filter(function (index) { 
    //return true/false based on specific logic 
    //'this' points to the element 
}); 
+0

谢谢,但是在我的环境中,你的代码无法工作。使用'不'过滤器,有没有其他解决方法? –

+0

@LeeCook你可以设置一个[jsfiddle](http://jsfiddle.net/)来显示你如何尝试实现?你有没有尝试过滤器? – plalx

相关问题