JSFiddle - React, Tailwind, and code Playground

by Lalji Tadhani

HTML

<table id="myTable"></table>

<button onclick="addRow();">+</button>
<button onclick="getData();">Done</button>

JavaScript

function addRow() {
    var table = document.getElementById("myTable");
    var row = table.insertRow(-1);

    cell1 = row.insertCell(0);
    cell1.innerHTML = '<input type="text"></input>';
    cell1.className = 'table-data';

    cell2 = row.insertCell(1);
    cell2.innerHTML = '<input type="text"></input>'; 
    cell2.className = 'table-data';
}


function getData() {
    inputCells = document.getElementById("table-data");

    for (var i = 0; i < inputCells.length(); i++) {
        console.log(inputCells[i].innerHTML);
}
}