Advertisement
gsmashik

add row click

Jun 26th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.45 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Document</title>
  6.  
  7. <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
  8. <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
  9.  
  10. <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
  11.  
  12. <style>
  13.  
  14.  
  15.  
  16.  
  17. </style>
  18. </head>
  19. <body>
  20. <div class="container">
  21.     <div class="row">
  22.       <div class="col-lg-12">
  23.           <h1>Table Records</h1>
  24.           <table class="table table-bordered table-hover" id="tableAddRow">
  25.               <thead>
  26.                   <tr>
  27.                       <th>User Name</th>
  28.                       <th>Email</th>
  29.                       <th>Password</th>
  30.                       <th style="width:10px"><span class="glyphicon glyphicon-plus addBtn" id="addBtn_0"></span></th>
  31.                   </tr>
  32.               </thead>
  33.               <tbody>
  34.                   <tr id="tr_0">
  35.                       <td><input type="text" id="userName" class="form-control"/></td>
  36.                       <td><input type="text" id="email" class="form-control" /></td>
  37.                       <td><input type="text" id="password" class="form-control" /></td>
  38.                       <td><span class="glyphicon glyphicon-minus addBtnRemove" id="addBtnRemove_0"></span></td>
  39.                   </tr>
  40.               </tbody>
  41.           </table>
  42.       </div>
  43.     </div>
  44. </div>
  45. <script>
  46.     $(document).ready(function () {
  47.     $('.addBtn').on('click', function () {
  48.         //var trID;
  49.         //trID = $(this).closest('tr'); // table row ID
  50.         addTableRow();
  51.     });
  52.      $('.addBtnRemove').click(function () {
  53.         $(this).closest('tr').remove();  
  54.     })
  55.     var i = 1;
  56.     function addTableRow()
  57.     {
  58.         var tempTr = $('<tr><td><input type="text" id="userName_' + i + '" class="form-control"/></td><td><input type="text" id="email_' + i + '" class="form-control" /></td><td><input type="text" id="password_' + i + '" class="form-control" /></td><td><span class="glyphicon glyphicon-minus addBtnRemove" id="addBtn_' + i + '"></span></td></tr>').on('click', function () {
  59.            $(this).closest('tr').remove();
  60.            $(document.body).on('click', '.TreatmentHistoryRemove', function (e) {
  61.                 $(this).closest('tr').remove();  
  62.             });
  63.         });
  64.         $("#tableAddRow").append(tempTr)
  65.         i++;
  66.     }
  67. });
  68. </script>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement