Use jQuery to wrap a div around a group of td's

Viewed 2419

Here is the example code I am working on:

<td class="one">content</td>
<td class="two">content</td>
<td class="three">content</td>
<td class="four">content</td>
<td class="five">content</td>

I am able to wrap a div around the first td using:

$('td.one').wrap('<div class="td-one">');

However, I now need to wrap the remaining four td's in a single div...so the desired outcome is:

<div class="td-one">
    <td class="one">content</td>
</div>
<div class="td-two-five">
    <td class="two">content</td>
    <td class="three">content</td>
    <td class="four">content</td>
    <td class="five">content</td>
</div>

How would I do this with jQuery?

2 Answers
Related