Reputation: 14270
I am trying to remove the some elements under a table cell.
my html is like
<table>
<tr>
<td>
<span>first text</span>
<span>second text</span>
<span>third text</span>
</td>
<td>
<span>1st text</span>
<span>2nd text</span>
<span>3rd text</span>
</td>
</tr>
…more
I want my html become
<table>
<tr>
<td>
<span>first text second text third text</span>
</td>
<td>
<span>1st text 2nd text 3rd text</span>
</td>
</tr>
…more
I have tried.
$('table td span').contents().unwrap().wrap('<span></span>');
but I got the same results as my original one.
Are there anyways to do this? Thanks a lot!
Upvotes: 2
Views: 103
Reputation: 27012
Need to iterate each td
and use wrapAll
instead of wrap
:
$('table td').each(function() {
$(this).find('span').contents().unwrap().wrapAll('<span></span>');
})
Upvotes: 5