<div class="test"> <div class="example"></div> </div> <div class="test"> </div>
How can I apply jQuery to an element with the class test
only if it doesn't contain a child element with the class example
?
filter(function() { return !$(
To select element that does not have specific class with JavaScript, we can use the document. querySelector method with the :not pseudoclass. const li = document. querySelector("li:not(.
When designing and developing web applications, sometimes we need to select all the child elements of an element except the last element. To select all the children of an element except the last child, use :not and :last-child pseudo classes.
To check if an HTML element has child nodes, you can use the hasChildNodes() method. This method returns true if the specified node has any child nodes, otherwise false . Whitespace and comments inside a node are also considered as text and comment nodes.
$('.test:not(:has(.example))')
-or-
$('.test').not(':has(.example)')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With