using while loop to create table rows js

Solutions on MaxInterview for using while loop to create table rows js by the best coders in the world

showing results for - "using while loop to create table rows js"
Naia
22 Jun 2016
1function newNode(node, text, styles) {
2  node.innerHTML = text;
3  node.className = styles;
4  return node;
5}
6
7var fragment = document.createDocumentFragment(),
8  container = document.getElementById("container");
9
10for(var i = 1; i <= 10; i++) {
11  var tr = document.createElement("tr");
12  var td = newNode(document.createElement("td"), i, "cell");
13  tr.appendChild(td);
14  fragment.appendChild(tr);
15}
16
17container.appendChild(fragment);
18