How to do dynamic html table on JS with jQuery? For example I must have 6 buttons:
- Add row to begin table;
- Add row to middle;
- Add row to end;
- Delete first row;
- Delete middle row;
- Delete last row;
UPD:
That's my JS:
$(document).ready(function(){
$('#addFirstPosition').click(function(){
var $tr = $('<tr><td>3</td><td>3</td></tr>');
//var $myTable = $('#myTable');
//$myTable.append($tr);
$("#myTable > tbody").append($tr);
);
});
And this is my html:
<input id="addFirstPosition" type="button" value="AddFirst" />
<input id="addMiddlePosition" type="button" value="AddMiddle" />
<input id="addLastPosition" type="button" value="AddLast" />
<br />
<input id="deleteFirstPosition" type="button" value="DelFirst" />
<input id="deleteMiddlePosition" type="button" value="DelMiddle" />
<input id="deleteLastPosition" type="button" value="DelLast" />
<br />
<br />
<table id="myTable" border="1px">
<tbody>
<tr>
<td>
1
</td>
<td>
1
</td>
</tr>
<tr>
<td>
2
</td>
<td>
2
</td>
</tr>
</tbody>
</table>
When I click to button, nothing happens.
buttontag instead of input. with your limited code it cannot be seen whether this is all in a form or not.<button type='button' id='someId'>value</button>