I'm new to dynamic javascript and I'm adding a button to my dynamic HTML table.
function addToTable(){
var table = document.getElementById("table");
var row = table.insertRow(counter + 1);
var removeRow=document.createElement("BUTTON");
var cell0 = row.insertCell(0)
var cell1 = row.insertCell(1);
var cell2 = row.insertCell(2);
var cell3 = row.insertCell(3);
cell0.innerHTML = counter + 1;
cell1.innerHTML = getName(array[counter]);
cell2.innerHTML = getEmail(array[counter]);
cell3.innerHTML = document.body.appendChild(removeRow);
counter++;
}
Whenever I run this, in the first the cells I get the index number, the name, and the email. in the 4th cell it prints "[object HTMLButtonElement]".
And an addition issue is when I assign a label on the button the entire method doesn't work. This is how I was adding a label.
var removeRow=document.createElement("BUTTON");
var text=document.createTextNode("Remove");
btn.appendChild(text);
document.body.appendChild(removeRow);
document.getElementById("table");do you really have an element withid="table"in your HTML?