0
I created a table with two buttons one has the function to add new rows to the table and another remove them.
I tested this way and can only add new lines, when I try to remove an error happens.
var table = $( '#table-data' )[0];
$( table ).delegate( '.tr_clone_add', 'click', function () {
var thisRow = $( this ).closest( 'tr' )[0];
$( thisRow ).clone().insertAfter( thisRow ).find( 'input:text' ).val( '' );
});
$( table ).undelegate( '.tr_clone_del', 'click', function () {
var thisRow = $( this ).closest( 'tr' )[0];
$( thisRow ).clone().delete( thisRow ).find( 'input:text' ).val( '' );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="table-data">
<tr>
<td>Name</td>
<td>Location</td>
<td>From</td>
<td>To</td>
<td>Add</td>
</tr>
<tr class="tr_clone">
<td><input type="text" autofocus placeholder="who" name="who"></td>
<td><input type="text" autofocus placeholder="location" name="location" ></td>
<td><input type="text" placeholder="Start Date" name="datepicker_start" class="datepicker"></td>
<td><input type="text" placeholder="End Date" name="datepicker_end" class="datepicker"></td>
<td><input type="button" name="add" value="Add" class="tr_clone_add"></td>
<td><input type="button" name="del" value="del" class="tr_clone_del"></td>
</tr>
</table>
I don’t understand what it is you’re asking. What exactly is your doubt?
– Victor Stafusa
with class "tr_clone_add" add new line and with class"tr_clone_del" I want to remove
– Groot