Take a look at Steve Brewer's enhancement:

<http://www.bigdumbdev.com/2007/09/replacehtml-remove-insert-put-back- 
is.html>

You don't lose the original node.

On Sep 13, 2007, at 9:50 AM, Tom Gregory wrote:

> Is there a "gotcha" with this code? (I haven't tested, and defer to  
> brighter minds than mine.)
>
> Because he's replacing the "target" node with a clone of itself  
> (code below), is there the potential to lose attached event  
> observers? That'd violate POLS.
>
> /* This is much faster than using (el.innerHTML = value) when there  
> are many
> existing descendants, because in some browsers, innerHTML spends  
> much longer
> removing existing elements than it does creating new ones. */
> function replaceHtml(el, html) {
>       var oldEl = (typeof el === "string" ? document.getElementById 
> (el) : el);
>       /[EMAIL PROTECTED] // Pure innerHTML is slightly faster in IE
>       oldEl.innerHTML = html;
>       return oldEl;
>       @*/
>       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;
> };
>
>
> TAG
>
> On Sep 13, 2007, at 9:01 AM, Ryan Gahl wrote:
>
>> um, oops: "duh, how _come_ ..." (missed a word)
>>
>> On 9/13/07, Ryan Gahl <[EMAIL PROTECTED]> wrote:
>> +1 for baking this into core, it's like "duh, how no one tested  
>> this before"
>>
>>
>> On 9/13/07, jdalton < [EMAIL PROTECTED]> wrote:
>>
>> Hi all,
>>
>> I was just reading on ajaxian that Steven Levithan has done some
>> benchmarks and found that innerHTML's main bottle neck is in its
>> destruction of existing nodes/elements. He has posted a new  
>> method. He
>> has benchmarks and a performance test as well. I figured it would be
>> an interesting addition to Element.update().
>>
>> http://blog.stevenlevithan.com/archives/faster-than-innerhtml
>> Anyone interested?
>>
>>
>>
>>
>>
>>
>>
>> -- 
>> Ryan Gahl
>> Manager, Senior Software Engineer
>> Nth Penguin, LLC
>> http://www.nthpenguin.com
>> --
>> Architect
>> WebWidgetry.com / MashupStudio.com
>> Future Home of the World's First Complete Web Platform
>> --
>> Inquire: 1-262-951-6727
>> Blog: http://www.someElement.com
>>
>>
>>
>> -- 
>> Ryan Gahl
>> Manager, Senior Software Engineer
>> Nth Penguin, LLC
>> http://www.nthpenguin.com
>> --
>> Architect
>> WebWidgetry.com / MashupStudio.com
>> Future Home of the World's First Complete Web Platform
>> --
>> Inquire: 1-262-951-6727
>> Blog: http://www.someElement.com
>>
>>
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to