Sorry just got an update, the tr class A and B are repeating a lot. I want to combine each AB into C and show all the Cs.
I got a table like this:
<table class="table">
<tbody>
<tr class="A">
<td>11111</td>
<td>22222</td>
<td>33333</td>
</tr>
<tr class="B">
<td>44444</td>
<td>55555</td>
<td>66666</td>
</tr>
<tr class="A">
<td>77777</td>
<td>88888</td>
<td>99999</td>
</tr>
<tr class="B">
<td>10101</td>
<td>11111</td>
<td>22222</td>
</tr>
</tbody>
</table>
What I want to do is some jQuery to combine the two tr together like:
<table class="table">
<tbody>
<tr class="C">
<td>11111</td>
<td>22222</td>
<td>33333</td>
<td>44444</td>
<td>55555</td>
<td>66666</td>
</tr>
<tr class="C">
<td>77777</td>
<td>88888</td>
<td>99999</td>
<td>10101</td>
<td>11111</td>
<td>22222</td>
</tr>
</tbody>
</table>
Here is a working example: http://jsfiddle.net/65XaF/
$(document).ready(function() {
var a = $('.A');
var b = $('.B');
a
.append(b.children())
.removeClass('A')
.addClass('C');
b.remove();
});
Note: question was updated to reflect multiple A & B groups after this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With