Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

dynamically add/remove rows in html table using javascript

<table id="myTable">
        <tr>
            <th>Record</th>
        </tr>
    </table>
    <button onclick="addRows()">Add Rows</button>

    <script>
        counter = 0;

        function addRows() {
            let table = document.querySelector("#myTable");
            let row = document.createElement("tr");
            let tableData = document.createElement("td");
            tableData.textContent = counter;
            counter += 1;

            table.appendChild(row)
            table.appendChild(tableData);
        }
    </script>
 
PREVIOUS NEXT
Tagged: #dynamically #rows #html #table #javascript
ADD COMMENT
Topic
Name
3+3 =