I am receiving JSON data from an API and I am populating this data into an HTML table using vanilla javascript. I am trying to add a button dynamically to the end of each row to perform some functionality, I haven't found a way to do it. Here is my function that populates the table with data
const showArtist = (data) => {
let tableStructure = `<table>
<thead>
<tr>
<th>Sr#</th>
<th>Name</th>
<th>Country</th>
<th>Disambiguation</th>
<th>Info</th>
</tr>
</thead>
<tbody id="tbody"></tbody>
</table>
`;
artistTable.innerHTML = tableStructure;
let tableBody = document.getElementById("tbody");
for (let i = 0; i < Object.keys(data).length; i++) {
let tr = "";
tr += `<tr>
<td>${i}</td>
<td>${data[i].name}</td>
<td>${data[i].country}</td>
<td>${data[i].disambiguation}</td>
<td><input type="button" value="" >Add</input></td>
</tr>`;
tableBody.innerHTML += tr;
}
};
I have tried using the appendChild method but it doesn't work either.
appendis Jquery methond, you should useappendChilddeveloper.mozilla.org/en-US/docs/Web/API/Node/appendChild