I have a HTML table as below :
<table> <tr> <th>Name</th> <th>Class</th> <th>Reg ID</th> </tr> <tr> <td>Alex</td> <td>VII</td> <td>56733</td> </tr> <div id="addfield"></div> </table> <input type="button" value="add" id="add_more_fields" /> And the jquery :
$(document).ready(function(){ var html = ''; $('#add_more_fields').click(function(){ html += '<tr>'; html += '<td>Steve</td>'; html += '<td>X</td>'; html += '<td>87777</td>'; html += '</tr>'; $('#addfield').append(html); }); }); I wanted to add the <tr> generated by the javascript to be within the table. but when I clicked the button, the output is shown outside the table ! How can I display it within the table ?
Tableinstead ofDiv[Updated Fiddle] (jsfiddle.net/2yBYb/1)