by
1
4
237k
0
Top 1% !
Popular
Pearl of Wisdom
Specified
Popularity: 5994th place
No tags for this snippet yet.
LanguageJavaScript
LicenseMIT_X11
SourceGitHub
SourceMyGists

Fastest way to add new nodes to the DOM

Fastest way to add new nodes to the DOM: 
frag.js
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/267374/Fastest-way-to-add-new-nodes-to-the-DOM?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
var frag = document.createDocumentFragment(); ajaxResult.items.forEach(function(item) { // Create the LI element var li = document.createElement('li'); li.innerHTML = item.text; // Do some normal node operations on the LI here, // like add classes, modify attributes, // add event listeners, add child nodes, etc. // *Instead place the LI into the fragment* frag.appendChild(li); }); // Lastly, mass-inject all list items via the DocumentFragment document.querySelector('ul').appendChild(frag);
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus