Element.replace (cp. Prototype)

1 view
Skip to first unread message

meik

unread,
Sep 1, 2008, 5:13:21 PM9/1/08
to MooTools Users
What I would really need is an Element.replace method that takes html
instead of taking an element.

The scenario is like the following:
I'm getting back some HTML from the server, which I want to use as a
replacement for an existing DOM Element.

The existing Element
<tr id="old_elem"><!-- old stuff here--></tr>

The HTML I want to use as a replacement
<tr id="new_elem"><!-- brand nu stuff here --></tr>

The Javascript I'm looking for would look like:

$('old_elem).replace('<tr id="new_elem"><!-- brand nu stuff here --></
tr>');

Or is there another way to go for this task?
Is it possible to convert HTML to an Element without attaching it to
the DOM before?
like an Element constructor that does not take a tagname?
myElem = new Element('<tr id="new_elem"><!-- brand nu stuff here --></
tr>');

Thanks so much!

>Meik

Jan Kassens

unread,
Sep 1, 2008, 5:39:45 PM9/1/08
to mootool...@googlegroups.com
set('html', str) does exactly that, but doesnt work for tables or trs
in IE yet, but we'll include a fix for that in the next release.

Jan

--
my blog: http://blog.kassens.net

meik

unread,
Sep 1, 2008, 5:49:06 PM9/1/08
to MooTools Users
Thanks Jan for the quick response!

The problem in my case is that I really wanna replace the old element.

By calling set('html',...) on the old element (the tr) I'm just
putting the contents inside, which results in a nested tr's in my case
(eg. <tr><tr></tr></tr> )

Michael

keif

unread,
Sep 2, 2008, 9:11:13 AM9/2/08
to MooTools Users
Here:

http://ramblings.gibberishcode.net/archives/cross-browser-ajax-updates-to-table-elements/9

I used a similar method for an AJAX form with dynamic insertion/
removal.

meik

unread,
Sep 3, 2008, 10:25:13 AM9/3/08
to MooTools Users
thanks a lot... exactly what I was looking for!

nevertheless, I would appreciate it if Mootools-Core would provide
methods for creating DOM Elements from plain HTML-fragments.

thanks,
Michael A.

On Sep 2, 3:11 pm, keif <god.dre...@gmail.com> wrote:
> Here:
>
> http://ramblings.gibberishcode.net/archives/cross-browser-ajax-update...
>
> I used a similar method for an AJAX form with dynamic insertion/
> removal.
>
> On Sep 1, 5:49 pm, meik <m...@zive.at> wrote:
>
> > Thanks Jan for the quick response!
>
> > The problem in my case is that I really wanna replace the old element.
>
> > By calling set('html',...) on the old element (the tr) I'm just
> > putting the contents inside, which results in a nested tr's in my case
> > (eg. <tr><tr></tr></tr> )
>
> > Michael
>
> > On Sep 1, 11:39 pm, Jan Kassens <jankass...@gmail.com> wrote:
>
> > > set('html', str) does exactly that, but doesnt work for tables or trs  
> > > in IE yet, but we'll include a fix for that in the next release.
>
> > > Jan
>
> > > On Sep 1, 2008, at 23:13, meik wrote:
>
> > > > What I would really need is anElement.replacemethod that takes html
Reply all
Reply to author
Forward
0 new messages