public
Created

  • Download Gist
innerHTML faster than fast
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// for everybody except IE
function replaceHtml(el, html) {
var oldEl = typeof el === "string" ? document.getElementById(el) : el;
var newEl = oldEl.cloneNode(false);
newEl.innerHTML = html;
oldEl.parentNode.replaceChild(newEl, oldEl);
/* Since we just removed the old element from the DOM, return a reference
to the new element, which can be used to restore variable references. */
return newEl;
};
 
// Pure innerHTML is slightly faster in IE, so change the function
/*@cc_on
function replaceHtml(el, html) {
var oldEl = typeof el === "string" ? document.getElementById(el) : el;
oldEl.innerHTML = html;
return oldEl;
}
@*/

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.