Cannot .remove an .append'ed row
Ok, Way cool how I can add a row by clicking "add". And just as great how I can delete a row by clicking "delete". But why, why, why can I not add a row, and then delete that row? Thank you!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
- <title>Testing</title>
-
- <script src="http://code.jquery.com/jquery-latest.js"></script>
-
- <script>
- $(function(){
- $(".delete_me").click(function()
- {
- row=$(this).parent().parent();
- if(window.confirm("Are you sure?"))
- {row.remove();}
- });
- $("#add_one").click(function()
- {
- var clone = $("#clone").clone();
- clone.removeAttr('class').removeAttr('id');
- $('td', clone).eq(0).text('Rochelle');
- $("#mytable tbody").append(clone);
- });
- });
- </script>
- <style type="text/css">
- .gone{display: none;}
- </style>
- </head>
- <body>
- <div>
- <a href="#" id="add_one">Add</a>
- <table id="mytable">
- <thead><tr><th>Name</th><th></th></tr></thead><tbody>
- <tr class="gone" id="clone"><td></td><td><a href="#" class="delete_me">Delete</a></td></tr>
- <tr><td>John</td><td><a href="#" class="delete_me" >Delete</a></td></tr>
- <tr><td>Mary</td><td><a href="#" class="delete_me" >Delete</a></td></tr>
- </tbody>
- </table>
- </div>
- </body>
- </html>