jQuery选择器 - 其中item没有具有特定类的子项

Tre*_*vor 9 jquery css-selectors

我想选择#nav的直接子项列表项,这些项目本身不具有"活动"类的直接子项.

这是我认为它应该是但它不起作用:

$('#nav > li:not(> a.active)')
Run Code Online (Sandbox Code Playgroud)

reg*_*bsb 25

这是你如何做到的:

    $('#nav > li:not(:has(a.active))')
Run Code Online (Sandbox Code Playgroud)


Ken*_*ing 11

你需要使用jQuery的filter功能:

$('#nav > li').filter(function() { return !($(this).children().is('.active')); })
Run Code Online (Sandbox Code Playgroud)