append

append

Hi.

I have two HTML tables, one with five td elements and another empty. I want to append an element from the fist table on the second table and delete it from the first table.

So here is code:

  1. <html> 
  2. <head>
  3. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  4. <script type="text/javascript">
  5. $(document).ready(function(){
  6. });
  7. </script>
  8. </head>  
  9. <body> 
  10. <script>
  11. $(document).ready(function(){
  12. var numElems = $('#data-source td').length;
  13. console.log("Before deleting there are " + numElems + " elements in the original collection");
  14. //I try to append one element to the second table and remove it from the first table
  15. $('#data-source:nth-child(1)').append('#new_table'); // DOESN'T WORK!
  16. $('#data-source td:nth-child(1)').remove(); // Yeah! It works!
  17. var numElems = $('#data-source td').length;
  18. console.log("After deleting there are " + numElems + " elements in the original collection");
  19. //Verification of thing's that doesn't work
  20. var numElems2 = $('#new_table td').length;
  21. console.log("There are " +numElems2+ " elements in the new collection");
  22. $('#new_table').css('display', 'block');
  23. });
  24. </script>
  25. <table id="data-source" align="center">
  26. <tr>
  27. <td>First element.</td>
  28. <td>Second element.</td>
  29. <td>Third element.</td>
  30. <td>Fourth element.</td>
  31. <td>Fifth element.</td>
  32. </tr>
  33. </table>
  34. <table id="new_table" align="center"></table>

  35. </body> 
  36.  </html> 
    My problem is in line 19.

    Can anyone help me? Any idea?

    Thank you very much.