When innerHTML isn’t Fast Enough[ZT]

http://blog.stevenlevithan.com/archives/faster-than-innerhtml

 1function 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

posted on 2008-06-01 00:10  yyliuliang  阅读(266)  评论(0编辑  收藏  举报

导航