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:
- <html>
- <head>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
-
- });
- </script>
- </head>
-
- <body>
- <script>
- $(document).ready(function(){
- var numElems = $('#data-source td').length;
- console.log("Before deleting there are " + numElems + " elements in the original collection");
-
- //I try to append one element to the second table and remove it from the first table
- $('#data-source:nth-child(1)').append('#new_table'); // DOESN'T WORK!
- $('#data-source td:nth-child(1)').remove(); // Yeah! It works!
- var numElems = $('#data-source td').length;
- console.log("After deleting there are " + numElems + " elements in the original collection");
-
- //Verification of thing's that doesn't work
- var numElems2 = $('#new_table td').length;
- console.log("There are " +numElems2+ " elements in the new collection");
- $('#new_table').css('display', 'block');
- });
- </script>
-
- <table id="data-source" align="center">
- <tr>
- <td>First element.</td>
- <td>Second element.</td>
- <td>Third element.</td>
- <td>Fourth element.</td>
- <td>Fifth element.</td>
- </tr>
- </table>
- <table id="new_table" align="center"></table>
- </body>
-
- </html>
My problem is in line 19.
Can anyone help me? Any idea?
Thank you very much.