2

I am trying to remove a row from one table and add it to another with jQuery. I've examined this similar Stack Overflow post and feel like I am doing roughly the same thing but am obviously missing something as what I am doing is not working. I know I've got the right row as the remove is working but the row is not being added to the new table.

jQuery

var row = $($.fn.colorbox.element()).parents('tr');
row.fadeOut(1000, function() {
    $('#NewTableBody').append(row.remove());
});

Table Body

<tbody id="NewTableBody">
Community
  • 1
  • 1
ahsteele
  • 26,243
  • 28
  • 134
  • 248

3 Answers3

4

If you're only looking to remove and append a single row you can try the closest() traversal function:

var $row = $($.fn.colorbox.element()).closest('tr');
$row.fadeOut(1000, function() {
    $('#NewTableBody').append($row);
    $row.fadeIn(1000);
});

Also your row is hidden (because of the fade out). You need to show it again.

Corey Ballou
  • 42,389
  • 8
  • 62
  • 75
2

Get rid of the remove() call, That is removing it from the DOM completely. append() will do the move for you.

var row = $($.fn.colorbox.element()).parents('tr');
row.fadeOut(1000, function() {
    $('#NewTableBody').append(row);
});
PetersenDidIt
  • 25,562
  • 3
  • 67
  • 72
1

try

var row = $($.fn.colorbox.element()).parents('tr');

row.fadeOut(1000, function() {
    $('#NewTableBody').append(row);
});
John Boker
  • 82,559
  • 17
  • 97
  • 130
  • Unfortunately, this does not work. The fadeout still occurs but the row is not appended to the `NewTableBody`. – ahsteele Dec 03 '09 at 18:58