jquery - clone nth row of a table?
Posted
by John
on Stack Overflow
See other posts from Stack Overflow
or by John
Published on 2010-05-02T18:06:47Z
Indexed on
2010/05/02
18:18 UTC
Read the original article
Hit count: 165
I'm trying to use jquery to clone a table row everytime someone presses the add-row button. Can anyone tell me what's wrong with my code? I'm using HTML + smarty templating language in my view. Here's what my template file looks like:
<table>
<tr>
<td>Description</td>
<td>Unit</td>
<td>Qty</td>
<td>Total</td>
<td></td>
</tr>
<tbody id="entries">
{foreach from=$arrItem item=i name=inv}
<tr>
<td>
<input type="hidden" name="invoice_item_id[]" value="{$i.invoice_item_id}"/>
<input type="hidden" name="assignment_id[]" value="{$i.assignment_id}" />
<input type="text" name="description[]" value="{$i.description}"/>
</td>
<td><input type="text" class="unit_cost" name="unit_cost[]" value="{$i.unit_cost}"/></td>
<td><input type="text" class="qty" name="qty[]" value="{$i.qty}"/></td>
<td><input type="text" class="cost" name="cost[]" value="{$i.cost}"/></td>
<td><a href="javascript:void(0);" class="delete-invoice-item">delete</a></td>
</tr>
{/foreach}
</tbody>
<tfoot>
<tr><td colspan="5"><input type="button" id="add-row" value="add row" /></td></tr>
</tfoot>
</table>
Here's my Jquery Javascript call, which I know gets fired when I put in an alert() statement. So the problem is with me not knowing how jquery works.
$('#add-row').live('click', function() {$('#entries tr:nth-child(0)').clone().appendTo('#entries');});
So what am I doing wrong?
© Stack Overflow or respective owner