Advertisement
VladimirZinchenko

Untitled

Mar 17th, 2020
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.88 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Title</title>
  6.     <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
  7. </head>
  8. <body>
  9. <table id="tbl">
  10.     <tr>
  11.         <td>1</td>
  12.         <td>2</td>
  13.     </tr>
  14. </table>
  15. <button id="addRow">add row</button>
  16.  
  17. <script>
  18.     const tableRow = `<tr><td>col1</td><td>col2</td></tr>`;
  19.  
  20.     $(document).ready(function () {
  21.       const tbl = $('#tbl')
  22.       $(document).on('click', '#addRow', function (e) {
  23.         e.preventDefault();
  24.         const cnt = tbl.find('tr').length;
  25.         const date = Date.now() + '';
  26.         const row = $(tableRow);
  27.         row.find('td:eq(0)').text(cnt);
  28.         row.find('td:eq(1)').text(date);
  29.         row.find('td').on('click', function () {
  30.           console.log(this);
  31.         })
  32.         tbl.append(row);
  33.       })
  34.     })
  35. </script>
  36. </body>
  37. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement