by
6
5
3,420
1
Top 1% !
Popular
Famous
Nice
Specified
Popularity: 3883rd place
This snippet is Public
No tags for this snippet yet.
LanguageJavaScript
LicenseMIT_X11
SourceGitHub

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/137720/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