Custom Repeater

by Rey Den Nalasa

HTML

<table width="100%" border="0" cellspacing="0" cellpadding="0" id="table-data">
    <tr>
        <td>Industry</td>
        <td>Data</td>
        <td>Industry</td>
        <td>Data</td>
        <td>Add</td>
    </tr>
    <tr class="tr_clone" data-count="1">
        <td><input type="text"  autofocus placeholder="Label" name="cb_lbl[]" ></td>
        <td><input type="text" autofocus placeholder="Number" name="cb_num[]" ></td>
        <td><input type="text" placeholder="Label" name="cb_lbl[]"></td>
        <td><input type="text" placeholder="Number" name="cb_num[]"></td>
        <td><input type="button" name="add" value="Add" class="tr_clone_add"></td>
    </tr>
</table><!-- /table#table-data -->

JavaScript

$("input.tr_clone_add").live('click', function() {
    var $tr    = $(this).closest('.tr_clone');
    var $clone = $tr.clone();
    
    $clone.find(':text').val('');
    $clone.attr('data-count', 2);
    $clone.data( "foo", 52 );
    $tr.after($clone);
});