Guest User

Untitled

a guest
Jul 19th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. function replaceHtml(el, html) {
  2. var oldEl = typeof el === "string" ? document.getElementById(el) : el;
  3. /* @cc_on // Pure innerHTML is slightly faster in IE
  4. oldEl.innerHTML = html;
  5. return oldEl;
  6. @*/
  7. var newEl = oldEl.cloneNode(false);
  8. newEl.innerHTML = html;
  9. oldEl.parentNode.replaceChild(newEl, oldEl);
  10. // Since we just removed the old element from the DOM, return a reference
  11. // to the new element, which can be used to restore variable references.
  12. return newEl;
  13. };
  14. // Example, replace #foo element with 2nd arg.
  15. //replaceHtml('foo','<div id="bar">Bar</div>');
Add Comment
Please, Sign In to add comment