I've been looking at all sorts of StackOverflow and Google answers, and I've not been able to figure this out.
What I'm trying to do, is add a row to one of many tables on my page. Right now, all "add row" requests add to the first table.
Here is my Javascript:
$(document).ready(function() {
$("a#add_row").click(function () {
$('#ListTable1').height($('#collapse1').height() + 60)
$("#delTable").find('tbody')
.append($('<tr>')
.append($('<td>')
.append('<input type="text" name="name[]" size="5"class="input input-small" />'))
.append($('</td>')
)
.append($('<td>')
.append('<input type="text" name="endpoint[]" size="5" class="input input-small" />'))
.append($('</td>')
)
.append($('<td style="width: 20px">')
.append()
.append($('</td>')
))
.append($('</tr>'))
);
});
});
And here is how I start each table:
<table class="table" id="listTable1" style="width: 280px;">
<thead>...the head...</thead>
<tbody>...all sorts of rows. Added row goes at the end of the tbody...</tbody>
<tfoot>
<tr>
<td><a id="add_row">Add Row</a></td><td></td>
</tr>
</tfoot>
</table>
And here is the button I'm using:
<a id="add_row">Add Row</a>
I know that I must increment the id for each table's ID, but I have no idea what to do with the Javascript to only add a row to the table that executed the request.
How can I get this to work?
$()asks jQuery to generate a new object. A lot of performance penalties going on there. Do something similar to :var tableRow = '<tr><td><input type="text" name="name[]" size="5" class="input input-small"/></td><td><input type="text" name="endpoint[]" size="5" class="input input-small" /></td><td style="width: 20px"></td></tr>'; $("#delTable").find('tbody').append(tableRow);