If I have a table as shown below, and have a up and down arrow that moves rows up and down, how would I go about swapping rows in JQuery?
-
Here is the code to swap the rows. Lets take #Row1 and #Row3
$('#Row1').replaceWith($('#Row3').after($('#Row1').clone(true)));
The clone(true) is used so that events are also taken into account.
If you want to move row up and down then use this code.
To move row UP
var tableRow = $("#Row1");
tableRow.insertBefore(tableRow.prev());
To move row DOWN
var tableRow = $("#Row1");
tableRow.insertAfter(tableRow.next());
- 热议问题