Tuesday, 20 October 2015

how to add and remove dynamically in table in jquery

@{
ViewBag.Title = "Index";



}
<input type="button" id="btn" value="Add More" />

<table id="tb">




</table>

<script src="~/Scripts/jquery-2.1.4.min.js"></script>

<script type="text/javascript">


$(function () {

$('#tb').append("<tr><td><input type='text' name='a' /></td><td><a href='#' name='d'>Delete</a></td></tr>");

$('#btn').click(function () {

$('#tb').append("<tr><td><input type='text' name='a' /></td><td><a href='#' name='d'>Delete</a></td></tr>");






});


$('#tb').on('click', "a[name='d']", function () {

if( $('#tb tr').length>1)

$(this).closest("tr").remove();






});


});








</script>



No comments:

Post a Comment