Jump to content

How to apply jQuery rule except if it is inside an element with certain class?


pstein

Recommended Posts

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 by pstein
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...