javascript - How to swap two sets of rows in a table -


i have 2 sets of rows in table selected:

var slice1 = $( table ).children( "tr" ).slice( - rowsperitem, ); var slice2 = $( table ).children( "tr" ).slice( i, + rowsperitem ); 

which can highlight using css , verify correct rows. want swap position in parent table set. 2 sets 1 after other in table , contain same number of rows.

everything i've tried moves 1 row:

$( slice1 ).after( slice2[slice2.length-1] ); 

how keep sets or rows together, in same order, swap position in table?

here's example of i'm seeing: http://jsfiddle.net/5vbfa/

try using insertafter method:

$("#swapbutton").click(function () {     var = 2;     var rowsperitem = 2;     var $tr = $("#thetable").find('tr');      var $slice1 = $tr.slice(i - rowsperitem, i);     var $slice2 = $tr.slice(i, + rowsperitem);      $slice1.insertafter($slice2[$slice2.length - 1]); }); 

http://jsfiddle.net/p2vsk/1/


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -