tags:

views:

275

answers:

3

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">
+1  A: 

try

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

row.fadeOut(1000, function() {
    $('#NewTableBody').append(row);
});
John Boker
Unfortunately, this does not work. The fadeout still occurs but the row is not appended to the `NewTableBody`.
ahsteele
+2  A: 

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
same answer at the (almost) same time.
John Boker
Unfortunately, this does not work. The fadeout still occurs but the row is not appended to the `NewTableBody`.
ahsteele
Without seeing a link to test it would be hard to tell you what is wrong
PetersenDidIt
+2  A: 

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.

cballou
Ah nice catch, didn't even think about it.
PetersenDidIt