Search
 
SCRIPT & CODE EXAMPLE
 

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>
Comment

PREVIOUS NEXT
Code Example
Javascript :: Reusable Alpine.js components 
Javascript :: react fragment inside map with key prop 
Javascript :: removeitem localstorage 
Javascript :: change li position in ul jquery 
Javascript :: vue js app component 
Javascript :: moment clone 
Javascript :: Appending the option element using jquery each function 
Javascript :: how to get input with name in jest test 
Javascript :: print array without brackets javascript 
Javascript :: vue computed 
Javascript :: es6 array to object keys 
Javascript :: javascript get second last element of array 
Javascript :: jquery selectors attribute ends with 
Javascript :: function countdown() 21 sec 
Javascript :: create a simple website using javascript 
Javascript :: js iife 
Javascript :: vuelidate required if another props 
Javascript :: Square star pattern in JavaScript 
Javascript :: search a word and separate in javascript 
Javascript :: add an object to an array mongosse 
Javascript :: javascript filter array match includes exact 
Javascript :: added font to react native 
Javascript :: convert int to string in angular 
Javascript :: cancel an event in javascript 
Javascript :: how to return the max and min of an array in javascript 
Javascript :: js reverse a number 
Javascript :: datatables modify rows 
Javascript :: how to add new line in jsx 
Javascript :: load url onclick javascript 
Javascript :: react code 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =