You'd be losing attached event observers anyway when you do a plain old .innerHTML = "..."
If anything, a one-step further implementation of this method would handle _removing_ any event handlers for you for memory management considerations (addressing potential circular reference based leaks that you would/should be dealing with manually anyway) On 9/13/07, Tom Gregory <[EMAIL PROTECTED]> 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 > > > > > > > -- 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 -~----------~----~----~----~------~----~------~--~---