Why are all children of an 'update'd element being purged?

6 views
Skip to first unread message

Viktor Kojouharov

unread,
Jul 2, 2010, 5:24:57 AM7/2/10
to Prototype: Core
This behaviour is a bit unexpected, and caused some debugging time to
figure out why some elements were losing their storage. Why isn't this
only done during page unload?

joe t.

unread,
Jul 2, 2010, 8:16:44 AM7/2/10
to Prototype: Core
Most people interpret it to mean "update with new content". Think
along the lines of a page refresh for just that element: wipe out the
existing content, update with new. Some others like yourself expect it
to mean "append with new content". That approach is handled by
Element#insert: preserve existing content, place new content at the
desired Position (usually appended, but insertion options are
available).

http://api.prototypejs.org/dom/element/insert/

This same question came up some months ago. Hopefully that
clarification helps.
-joe t.

Viktor Kojouharov

unread,
Jul 3, 2010, 6:00:18 AM7/3/10
to Prototype: Core
I understand that. And I was using update to clear the container and
add a new element. My problem was, I have a reference to the previous
element of the container that was just cleared, and I am saving that
reference of the element with the intention of replacing the new
container content with that element at some future time. Right now I'm
using innerHTML = '', since using Element#update would wipe out the
storage of the element I have a reference to, and that is highly
undesirable.

Allen Madsen

unread,
Jul 3, 2010, 6:42:55 AM7/3/10
to prototy...@googlegroups.com
Element#replace may be what you are looking for.

Allen Madsen
http://www.allenmadsen.com

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

joe t.

unread,
Jul 3, 2010, 11:19:00 AM7/3/10
to Prototype: Core
Thanks for the clarification.

Most methods that change content destroy the old content in favor of
the new. The same is true for #replace suggested above.

If you need to retain content while putting new content in its place,
you may need a deep-clone method (which i've requested in the past and
someone provided a possibility as an extension, but i couldn't get it
to work). A search on this group for "deep clone" brings up a thread
with a similar method and suggestions of additional arguments to
control the amount of storage that gets copied.

Another alternative could be to move the containers you need to
preserve to some other, hidden, parent container before placing the
new content.

Sorry i wasn't more helpful. i'm a little rusty of late, being pressed
for more C# development than web work lately. i hope one of the big-
brains here can take a look and offer something for you.
-joe t.
Reply all
Reply to author
Forward
0 new messages