Evanss
Evanss

Reputation: 23593

jQuery unwrap only if parent has class

Im using jQuery's unwrap function however I want it to only unwrap if the parent div (the one to be deleted) has a certain class.

I was using this:

$('.children').unwrap();

I tried changing it to this, so the parent would only be removed if it has a class of 'parent', but the code behaves the same as above. Thanks

$('.children').unwrap('.parent');

Upvotes: 2

Views: 3750

Answers (1)

Andreas Wong
Andreas Wong

Reputation: 60536

$('.parent > .children').unwrap();

Try the above :)

Upvotes: 11

Related Questions