Jonathan Boutelle
2006-Jan-08 00:38 UTC
Replacing an html chunk with a different html chunk
All, I''m a big fan of the Insertion.* classes in prototype (Insertion.Before, Insertion.After, Insertion.Top, Insertion.Bottom). These classes solve the problem of adding new html to existing html in the desired place. Very useful. But what about replacing one chunk of HTML with another? Or removing a specific chunk of HTML? These tasks come up just as often. 1)Am I correct that Prototype doesn''t solve this problem? 2)If so, what''s the best way to do this? Regards, ----^-------^------^--------^-------^ Jon Boutelle Principal, Uzanto Consulting Mountain View, CA Office Phone:650-564-0000 skype id: jboutelle www.uzanto.com www.jonathanboutelle.com www.themindcanvas.com ----^-------^------^--------^-------^
I have some code replaces an existing HTML element with new HTML. It can be
found here:
http://blog.craz8.com/articles/2005/12/15/rails-rjs-templates-need-better-re
place-semantics
The last chunk of code in that entry is an extension to the Element class
that allows you to say:
Element.replace(''foo'', ''<div
id="foo">...</div>'');
Just add this to somewhere in your own JS code to use it.
You can also use this code to remove an element, but there may be a better
way to do this:
Element.replace(''foo'', '''');
I''ve submitted this to Sam as a Prototype update.
-----Original Message-----
From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
[mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]
On Behalf Of Jonathan
Boutelle
Sent: Saturday, January 07, 2006 4:38 PM
To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Subject: [Rails-spinoffs] Replacing an html chunk with a different html
chunk
All,
I''m a big fan of the Insertion.* classes in prototype
(Insertion.Before, Insertion.After, Insertion.Top, Insertion.Bottom).
These classes solve the problem of adding new html to existing html
in the desired place. Very useful.
But what about replacing one chunk of HTML with another? Or removing
a specific chunk of HTML? These tasks come up just as often.
1)Am I correct that Prototype doesn''t solve this problem?
2)If so, what''s the best way to do this?
Regards,
----^-------^------^--------^-------^
Jon Boutelle
Principal, Uzanto Consulting
Mountain View, CA
Office Phone:650-564-0000
skype id: jboutelle
www.uzanto.com
www.jonathanboutelle.com
www.themindcanvas.com
----^-------^------^--------^-------^
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 1/7/06, Jonathan Boutelle <jon-A5IfmvDjiG/QT0dZR+AlfA@public.gmane.org> wrote:> All, > > I''m a big fan of the Insertion.* classes in prototype > (Insertion.Before, Insertion.After, Insertion.Top, Insertion.Bottom). > These classes solve the problem of adding new html to existing html > in the desired place. Very useful. > > But what about replacing one chunk of HTML with another? Or removing > a specific chunk of HTML? These tasks come up just as often. > 1)Am I correct that Prototype doesn''t solve this problem? > 2)If so, what''s the best way to do this? > > Regards,elem.innerHtml = ''other html''; This was actually the original and only way to update content w/ prototype IIRC :) As for removing a node... elem.parentNode.removeChild(elem); -- rick http://techno-weenie.net