Skip to content

Instantly share code, notes, and snippets.

@Archie22is
Last active November 2, 2015 08:26
Show Gist options
  • Select an option

  • Save Archie22is/ebc405c4d729389e5a19 to your computer and use it in GitHub Desktop.

Select an option

Save Archie22is/ebc405c4d729389e5a19 to your computer and use it in GitHub Desktop.
Creating HTML tables with JavaScript/DOM methods
function createTable() {
var i=0, rowEl=null,
tableEl = document.createElement("table");
// create 10 table rows, each with two cells
for (i=1; i <= 10; i++) {
rowEl = tableEl.insertRow(); // DOM method for creating table rows
rowEl.insertCell().textContent = "table cell "+ i +"-1" ;
rowEl.insertCell().textContent = "table cell "+ i +"-2" ;
}
document.body.appendChild( tableEl);
}
@Archie22is
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment