I have the following jquery code to add and remove a row in a table. I have multiple tables on one page. Each row in each table has these two classes: .row-add and .row-delete
Now when I click on '.row-add'to add a new row, all the tables are affected, meaning that row is added to all of the tables on the same page. What should I do to make it only apply to its own table when clicked?
Jquery:
$(document).ready(function () {
$('.row-delete').click(function () {
$(this).closest("tr").remove();
});
$('.row-add').click(function () {
$(this).closest("tr").clone(true).appendTo(".table-comparison");
});
});
Html:
<div id="tab-1" class="tab-section">
<div class="container flat rounded-sm bspace">
<table cellspacing="0" class="display table-comparison">
<thead>
<tr>
<th><span>Effective Date</span></th>
<th><span>Price</span></th>
</tr>
</thead>
<tbody>
<tr>
<td><input class="effective-date" type="text" value="01/01/2013"> - <input class="effective-date" type="text" value="06/05/2015">
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
<td>
$<input class="price" value="50">
/
<select>
<option>Second</option>
<option>Minute</option>
<option>Hour</option>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
</select>
/
<select>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
<option>Month</option>
<option>Quarter</option>
<option>Year</option>
</select>
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
</tr>
<tr class="price-present">
<td><input class="effective-date" type="text" value="07/01/2013"> - <span class="effective-date">Present</span>
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
<td>
$<input class="price" value="40">
/
<select>
<option>Second</option>
<option>Minute</option>
<option>Hour</option>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
</select>
/
<select>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
<option>Month</option>
<option>Quarter</option>
<option>Year</option>
</select>
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
</tr>
<tr>
<td><input class="effective-date" type="text" value="01/01/2011"> - <input class="effective-date" type="text" value="06/30/2012">
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
<td>
$<input class="price" value="30">
/
<select>
<option>Second</option>
<option>Minute</option>
<option>Hour</option>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
</select>
/
<select>
<option>Day</option>
<option>Week</option>
<option>Biweek</option>
<option>Month</option>
<option>Quarter</option>
<option>Year</option>
</select>
<span class="row-add"></span>
<span class="row-delete"></span>
</td>
</tr>
</tbody>
</table>
</div>
</div>