Skip to content Skip to sidebar Skip to footer

Jquery Select Elements That Do Not Contain A Class

How do I use not selector here? I would like to select all the classes '.hi' that do not contain class '.image'. HTML

Solution 1:

To do it just with a selector, you'd use :not with :has:

$(".hi:not(:has(.image))")
// or to be more specific:
$(".hi:not(:has(.hue > .image))")

Note that :has is jQuery-specific.

To do it with filter, you could use find in the callback:

$(".hi").filter(function() { return $(this).find(".image").length == 0; })
// or to be more specific:
$(".hi").filter(function() { return $(this).find(".hue > .image").length == 0; })

Post a Comment for "Jquery Select Elements That Do Not Contain A Class"