pstein Posted July 20, 2022 Share Posted July 20, 2022 (edited) Sample HTML code: <div class="foobar" ...> <div class="subelem" .....> <figure>. first figure....</figure> </div> </div> <figure>. second figure....</figure> Now I want to remove all <figure> elements which are NOT (!) inside an element with a class=foobar If I code this with jQuery: $("figure").remove(); then ALL <figure> elements are removed. How can I restrict the removal to only <figure> elements OUTSIDE of element with a class=foobar? In the sample code above only the second figure should be removed Be aware the element with class=foobar need not to be the direct parent element of <figure> Edited July 20, 2022 by pstein Link to comment Share on other sites More sharing options...
dsonesuk Posted July 20, 2022 Share Posted July 20, 2022 $("div:not('.foobar') figure").remove(); Should work. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now