jquery not选择器不工作

jquery not selector not working

本文关键字:工作 选择器 not jquery      更新时间:2023-09-26

我正在尝试用以下方式选择父类"searchresultitem",跳过其中的h3标记,并从选择中选择btn-gray类。我的代码在这里

$('div.search-result-item:not(h3 .btn-grey)').click(function(e){
    console.log('1');
});

但它选择了h3和btn-gray我也做错了什么?

Try,

$('div.search-result-item').find(":not('h3'),:not('.btn-grey')")

或者wolf建议的更好的解决方案,

$('div.search-result-item :not("h3,.btn-grey")')

试试看:

$('div.search-result-item').not('h3 .btn-grey').click(function(e){
    console.log('1');
});

您可能需要查看":has()"选择器,http://api.jquery.com/has-selector/。

$("div.search-result-item:not(:has(h3.btn-grey)")