Skip to content

Instantly share code, notes, and snippets.

@spencerwi
Created November 13, 2013 20:21
Show Gist options
  • Save spencerwi/7455703 to your computer and use it in GitHub Desktop.
Save spencerwi/7455703 to your computer and use it in GitHub Desktop.
Poor-man's DocumentFragment using display:none
/* Again, the assumption: arrayOfElements is an array of DOM nodes created from a template or otherwise. */
/* We can set our targetNode to "display:none", change it, and then reset it, making it into a poor man's DocumentFragment */
var targetNode = document.getElementById('target');
var previousDisplayValue = targetNode.style.display;
targetNode.style.display="none"; /* 1 reflow */
var appendToNode = targetNode.appendChild.bind(targetNode);
arrayOfElements.forEach(appendtoTargetNode); /* 0 reflows */
targetNode.style.display = previousDisplayValue; /* 1 reflow */
/* Total: 2 reflows */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment