Created
March 25, 2011 20:37
This file contains 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
// 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; | |
} | |
@*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment