Reputation: 5712
For example, I have this code:
<table>
<tr>
<td class="last"></td>
<td></td>
</tr>
<tr>
<td class="last"></td>
<td></td>
</tr>
<tr>
<td class="another"></td>
<td></td>
</tr>
<tr>
<td class="another"></td>
<td></td>
</tr>
</table>
I want this to be set like this using javascript:
<table>
<tr>
<td class="another"></td>
<td></td>
</tr>
<tr>
<td class="another"></td>
<td></td>
</tr>
<tr>
<td class="last"></td>
<td></td>
</tr>
<tr>
<td class="last"></td>
<td></td>
</tr>
</table>
Just what is needed is, javascript should detect td with class "last" and take whole table row to bottom of the table.
Upvotes: 0
Views: 886
Reputation: 144699
try this:
$('td').each(function(){
if ($(this).hasClass('another')) {
$(this).insertBefore($('td:first'))
}
})
Upvotes: 0
Reputation: 2583
Try this...
$("table tr td.last").each(function () {
$(this).parent().insertAfter($("table tr:last"));
});
Upvotes: 0
Reputation: 11
You can use this plugin: http://tablesorter.com/docs/#Demo
Something more advanced: http://www.trirand.com/blog/jqgrid/jqgrid.html
Upvotes: 1
Reputation: 60777
var last = $( '.last' );
last.parent().parent().append( last.parent() );
last.parent().parent()
is the table
element, and last.parent()
is the tr
element.
append
moves the DOM elements, so they're not "copied", they're moved to the end.
Upvotes: 1