using jquery to add tr
Posted
by user306472
on Stack Overflow
See other posts from Stack Overflow
or by user306472
Published on 2010-04-02T19:07:47Z
Indexed on
2010/04/02
19:13 UTC
Read the original article
Hit count: 388
I added a jquery function to add a <tr>
dynamically at the end of my table. It worked fine until I added table headers to my table. After I did this, the function started adding 2 trs at a time to the table. What happened?
HTML:
<table id="table" border="0">
<th>Col 1</th><th>Col2</th><th>col3</th>
<tbody>
<tr>
<td>
<select>
<option value ="one">one</option>
<option value="two">two</option>
</select>
</td>
<td>
<input type="text"></input>
</td>
<td>
<input type="text"></input>
</td>
</tr>
</tbody>
</table>
JQuery code:
$(function(){
$('a#add').click(function(){
$('#table > tbody').append('<tr><td><select><option value ="one">one</option><option value="two">two</option></select></td><td><input type="text"></input></td><td><input type="text"></input></td></tr>');
});
© Stack Overflow or respective owner