Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <title>HTML Table Insert Demo</title>
- </head>
- <body>
- <style>
- table {
- font-family: arial, sans-serif;
- border-collapse: collapse;
- width: 100%;
- }
- td, th {
- border: 1px solid #dddddd;
- text-align: left;
- padding: 8px;
- }
- tr:nth-child(even) {
- background-color: #dddddd;
- }
- </style>
- <body>
- <p>Click the button to add a new row at the first position of the table and then add cells and content.<br>
- <button onclick="myFunction()">Try it</button><br>
- </p>
- <table id="myTable">
- <tr>
- <td>ROW:3 CELL:A</td>
- <td>ROW:3 CELL:B</td>
- </tr>
- <tr>
- <td>ROW:2 CELL:A</td>
- <td>ROW:2 CELL:B</td>
- </tr>
- <tr>
- <td>ROW:1 CELL:A</td>
- <td>ROW:1 CELL:B</td>
- </tr>
- </table>
- <br>
- <script>
- var counter = 4;
- function myFunction() {
- var table = document.getElementById("myTable");
- var row = table.insertRow(0);
- var cell1 = row.insertCell(0);
- var cell2 = row.insertCell(1);
- var string_counter = counter.toString()
- cell1.innerHTML = "ROW:" + string_counter + " CELL:A (New)";
- cell2.innerHTML = "ROW:" + string_counter + " CELL:B (New)";
- counter++;
- }
- </script>
- </body>
- </html>
- </body>
- </html>
Add Comment
Please, Sign In to add comment