1
<script>
function onButtonClick()
{
var table1 = document.createElement('table');

    for(i=0;i<3;i++)
    {

    var td1 = document.createElement('td');
    var text1 = document.createTextNode(a[i]);
    td1.appendChild(text1);
    tr.appendChild(td1);
    td1.style.borderStyle = "solid";
    td1.style.padding = "10px";
    }

}
</script>

So whenever button is clicked the table row is appended.How to delete row or table after function has been loaded once.I wanted to replace old value of a[i] with new value of a[i]

2 Answers2

0

You will need to give each of your table elements a unique id:

table1.setAttribute("id", "<your id here>");

Then you can remove the table by accessing it via it's id and unsetting its outerHTML property:

document.getElementById("<table id here>").outerHTML = "";
Ryan Tuosto
  • 1,941
  • 15
  • 23
0

You need to set ID for your table such as:

var table1 = document.createElement('table');
table1.setAttribute("id", "DynamicTable");

**Here

DynamicTable

is the element ID defined by you. Rename it as your preference.

And then remove element by their ID. To remove elements by ID, have a look at this: https://stackoverflow.com/a/18120786/4190159

Somdip Dey
  • 3,346
  • 6
  • 28
  • 60