Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Title</title>
- <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
- </head>
- <body>
- <table id="tbl">
- <tr>
- <td>1</td>
- <td>2</td>
- </tr>
- </table>
- <button id="addRow">add row</button>
- <script>
- const tableRow = `<tr><td>col1</td><td>col2</td></tr>`;
- $(document).ready(function () {
- const tbl = $('#tbl')
- $(document).on('click', '#addRow', function (e) {
- e.preventDefault();
- const cnt = tbl.find('tr').length;
- const date = Date.now() + '';
- const row = $(tableRow);
- row.find('td:eq(0)').text(cnt);
- row.find('td:eq(1)').text(date);
- row.find('td').on('click', function () {
- console.log(this);
- })
- tbl.append(row);
- })
- })
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement