Table row cloning: remove data from row before clone
I am currently using this function to clone rows in my table when a user clicks 'add row'
- $(document).ready(function() {
- $("#addrow").click(function() {
- var row = $('#answer_options tbody>tr:last').clone(true).insertAfter('#answer_options tbody>tr:last');
- $("td:eq(2)", row).text($("#answer_options tbody>tr").length);
- $("td:eq(4) input", row).attr("name", "choice_text")
- $("td:eq(5) input", row).attr("name", "blah")
- return false;
- });
The problem is, obviously, cloning the row also clones any of the data that the user may have already entered. I need to just clone the elements of the row, not the user entered data. Is there a way to remove all data from a row before it is cloned?