Last active
November 2, 2015 08:26
-
-
Save Archie22is/ebc405c4d729389e5a19 to your computer and use it in GitHub Desktop.
Creating HTML tables with JavaScript/DOM methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference: http://www.codeproject.com/Articles/1036671/Creating-HTML-tables-with-JavaScript-DOM-methods