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's a slightly expanded example, hoping you will find it useful... :)
$('table').on('click', '.move-up', function () {
var thisRow = $(this).closest('tr');
var prevRow = thisRow.prev();
if (prevRow.length) {
prevRow.before(thisRow);
}
});
$('table').on('click', '.move-down', function () {
var thisRow = $(this).closest('tr');
var nextRow = thisRow.next();
if (nextRow.length) {
nextRow.after(thisRow);
}
});
- 热议问题