jQuery选择不包含类的元素
我如何在这里使用不是选择器? 我想选择所有不包含类“.image”的类“.hi”。
HTML
456 123 here
JS
我试过这样的东西,但它没有用。
console.log($('.hi').find('.hue > :not(.image')));
要使用选择器来执行此操作,您可以使用:not
with :has
:
$(".hi:not(:has(.image))") // or to be more specific: $(".hi:not(:has(.hue > .image))")
请注意:has
是特定于jQuery的。
要使用filter
,您可以在回调中使用find
:
$(".hi").filter(function() { return $(this).find(".image").length == 0; }) // or to be more specific: $(".hi").filter(function() { return $(this).find(".hue > .image").length == 0; })