Search code examples
javascriptdomdhtml

insertRow vs. appendChild


Which method is preferred for adding a row to a table?

var tr = tbl.insertRow(-1);

or

var tr = document.createElement('tr'); tbl.appendChild(tr);

?


Solution

  • insertRow would be the much better. It is supported by grade A browsers and it's less verbose and a cleaner API.