Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery combine two tr class into one

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>
like image 549
Simpledog Avatar asked Feb 20 '26 02:02

Simpledog


1 Answers

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.

like image 181
Cymen Avatar answered Feb 27 '26 10:02

Cymen