"Dynamic Table row creation and Deletion"
Bootstrap 3.0.3 Snippet by nifrasismail

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row clearfix"> <div class="col-md-12 column"> <table class="table table-bordered table-hover" id="tab_logic"> <thead> <tr > <th class="text-center"> # </th> <th class="text-center"> Item ID </th> <th class="text-center"> Item Name </th> <th class="text-center"> Position X </th> <th class="text-center"> Position Y </th> <th class="text-center"> Inside Element </th> <th class="text-center"> Action </th> <th class="text-center"> Display Time </th> <th class="text-center"> Diplay Key Note </th> </tr> </thead> <tbody> <tr id='addr0'> <td> 1 </td> <td> <input type="text" name='id' placeholder='Item Id' class="form-control"/> </td> <td> <input type="text" name='name' placeholder='Item Name' class="form-control"/> <td> <input type="text" name='x' placeholder='X-Position' class="form-control"/> </td> <td> <input type="text" name='y' placeholder='Y-Position' class="form-control"/> </td> <td> <input type="text" name='inside' placeholder='Inside Element' class="form-control"/> </td> <td> <input type="text" name='action' placeholder='Action' class="form-control"/> </td> <td> <input type="text" name='holdingTime' placeholder='Display Time' class="form-control"/> </td> <td> <input type="text" name='notes' placeholder='Display Key Note' class="form-control"/> </td> </tr> <tr id='addr1'></tr> </tbody> </table> </div> </div> <a id="add_row" class="btn btn-default pull-left">Add Row</a><a id='delete_row' class="pull-right btn btn-default">Delete Row</a> </div>
$(document).ready(function(){ var i=1; $("#add_row").click(function(){ $('#addr'+i).html("<td>"+ (i+1) +"</td><td><input name='name"+i+"' type='text' placeholder='Name' class='form-control input-md' /> </td><td><input name='mail"+i+"' type='text' placeholder='Mail' class='form-control input-md'></td><td><input name='mobile"+i+"' type='text' placeholder='Mobile' class='form-control input-md'></td>"); $('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>'); i++; }); $("#delete_row").click(function(){ if(i>1){ $("#addr"+(i-1)).html(''); i--; } }); });

Related: See More


Questions / Comments: