My application features a form that allows users to dynamically add new rows to a table using JavaScript:
// Function to add a new account row
if (tit.innerHTML === "Add Account"){
var table = document.getElementById(tableId);
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.innerHTML = document.getElementById("modal_type").value;
cell2.innerHTML = document.getElementById("modal_price").value;
}
In addition to adding new rows, I am trying to include an edit button in each newly created row with a specified "td" class.
<td class=edtbutton><button class="edit_account" data-modal-target="#modal" id="editaccounts" onclick="sayedit()">✎</button></td>
I attempted to declare a variable called cell3 and insert the button code into it using cell3.innerHTML, but this did not work. Additionally, I tried concatenating the strings with += but encountered similar issues.