I am currently attempting to duplicate a row from one table into a new table and then include an additional td at the end of the copied row containing a delete button.
Thus far, I have successfully duplicated the row but am struggling to find a method for adding the new td.
var items = [];
$('.addme').click(function() {
var $this = $(this);
$this.toggleClass('addme');
if ($this.hasClass('addme')) {
$this.val('Add').toggleClass('added');
} else {
$this.val('Added').toggleClass('added');
var newTr = $(this).closest("tr").clone();
items.push(newTr);
newTr.appendTo($("#products_chosen"));
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="products" class="table table-bordered table-striped table-shopsite display" cellspacing="0">
<thead>
<tr>
<th>ID</th>
<th>Manufacturer</th>
<th>Name</th>
<th>Country</th>
<th>Price per kg.</th>
<th>Quantity</th>
<th>Favorite</th>
<th></th>
</tr>
</thead>;
<tr>
<td>1726</td>
<td>Danroots</td>
<td>Carrot</td>
<td>Denmark</td>
<td>5 kr</td>
<td><input type="number" value="" class="qty" name="qty"></input>
</td>
<td><i class="heart fa fa-heart-o fa-2x"></i></td>
<td><input type="button" id="add" class="addme" Value="Add"></input>
</td>
</tr>>;
<tr>
<td>1726</td>
<td>Danroots</td>
<td>Carrot</td>
<td>Germany</td>
<td>5 kr </td>
<td><input type="number" value="" class="qty" name="qty"></td>
<td><i class="heart fa fa-heart-o fa-2x"></i></td>
<td><input type="button" class="addme" Value="Add"></input>
</td>
</tr>;
<tr>
<td>1726</td>
<td>Danroots</td>
<td>Cucumber</td>
<td>Spain</td>
<td>5kr</td>
<td><input type="number" value="" class="qty" name="qty"></td>
<td><i class="heart fa fa-heart-o fa-2x"></i></td>
<td><input type="button" class="addme" Value="Add"></input>
</td>
</tr>;
</table>;
<br>; <br>; <br>;
<div class="table">
<table id="products_chosen" class="table table-bordered table-striped table-shopsite display" cellspacing="0">
<thead>
<tr class="active">
<th>ID</th>
<th>Manufacturer</th>
<th>Name</th>
<th>Country</th>
<th>Price per kg.</th>
<th>Quantity</th>
<th>Favorite</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody <tr>
</tr>
</tbody>
<tfoot>
<tr>
</tr>
</tfoot>
</table>