How to insert row at end of table with HTMLTableElement.insertRow

后端 未结 4 1844
天命终不由人
天命终不由人 2020-12-05 19:07

Background and Setup

I\'m trying to create a table from tabular data in javascript, but when I try inserting rows into a table element, it inserts in the opposite

4条回答
  •  我在风中等你
    2020-12-05 19:28

    You can do this,

    var table = document.getElementById("yourTable");
    var row = table.insertRow(-1);
    
    var cell1 = row.insertCell(0);
    var cell2 = row.insertCell(1);
    var cell3 = row.insertCell(2);
    var cell4 = row.insertCell(3); 
    

提交回复
热议问题