Skip to content

Instantly share code, notes, and snippets.

@ksss
Created January 19, 2013 08:54
Show Gist options
  • Save ksss/4571509 to your computer and use it in GitHub Desktop.
Save ksss/4571509 to your computer and use it in GitHub Desktop.
Fast insert Text on HTML
function appendHTML(elm,htm) {
if (document.createRange) {
var rangeObj = document.createRange ();
rangeObj.selectNodeContents(document.body);
if (rangeObj.createContextualFragment) {
// all browsers, except IE
var documentFragment = rangeObj.createContextualFragment(htm);
elm.insertBefore (documentFragment, elm.firstChild);
} else {
// Internet Explorer from version 9
elm.insertAdjacentHTML("afterBegin", htm);
}
} else {
// Internet Explorer before version 9
elm.insertAdjacentHTML("afterBegin", htm);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment