Invert table rows
fiddle
pretty much the same as the other guy, only I use .detach() which is guarunteed to keep any crazy events that were attached to the tr
s intact. I also use $.makeArray to avoid reversing any of the proto
stuff on the base jQuery object.
$(function(){
$("tbody").each(function(elem,index){
var arr = $.makeArray($("tr",this).detach());
arr.reverse();
$(this).append(arr);
});
});
Try this:-
Get the array of tr
s from tbody
using .get()
and use Array.reverse to reverse the elements and assign it back.
var tbody = $('table tbody');
tbody.html($('tr',tbody).get().reverse());
Fiddle
In case you have events to tr
or any containing elements you could just attach it using delegation, so that the reversed elements also get them delegated.
Demo
$('tbody').each(function(){
var list = $(this).children('tr');
$(this).html(list.get().reverse())
});
Demo -->
http://jsfiddle.net/ZaUrP/5/