Created
May 21, 2014 17:22
-
-
Save a-axton/8a5a6cdb379655b47eff to your computer and use it in GitHub Desktop.
Document fragments
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
| var table = document.getElementById('t'); | |
| var tr = table.querySelector('tr'); | |
| var th = document.createElement('th'); | |
| var clone; | |
| var df = document.createDocumentFragment(); | |
| for (var i = 0; i < 100; i++) { | |
| // Performance tip: clone a node so that you don't reuse createElement() | |
| clone = th.cloneNode(); | |
| clone.appendChild(document.createTextNode('hello' + i)); | |
| // Performance tip: append to the document fragment | |
| df.appendChild(clone); | |
| } | |
| // Performance tip: append only once in the real DOM | |
| tr.appendChild(df); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment