Reputation: 627
Is there a way to use the .unwrap
function to unwrap all instances of a specific class (in this case 'blah')
<div class="blah">
<a href="http://google.com">Google</a>
</div>
<div class="blah">
<span>Testing</span>
</div>
Right now, I'm using a code like this:
$('.blah a').unwrap();
But this wouldn't unwrap the second piece of code with the span
in it above.
Upvotes: 3
Views: 6702
Reputation: 529
I found an issue with the accepted answer to this question. jQuery's .children()
method doesn't return any of the text nodes. Meaning that any content under the div that is not wrapped in another element will get stripped.
This is my solution:
$('.blah').replaceWith(function () {
return this.childNodes;
});
Upvotes: 5
Reputation: 196002
How about
$('.blah').children().unwrap();
Demo at http://jsfiddle.net/gaby/KAzgq/
Upvotes: 11