first, there is nothing wrong with the way you are doing it.
other options:
// replace/update the contents of mydiv
Element.update(''mydiv'', ''new content'')
// hide (set display style to ''none'')
Element.hide(''mydiv'')
// removes element from document
Element.remove(''mydiv'')
example
<%= form_remote_tag :update => "update_div", :url => {
:action =>
"do_something" }, :success =>
"Element.update(''some_other_div'',
'''')" %>
<%= end_form_tag %>
<div id="update_div"></div>
<div id="some_other_div"></div>
so what the above does is 2 things:
its updates the "update_div" with the results of the ajax call to the
do_something action, then, upon success, replaces (updates) the
"some_other_div" with *blank*
you could accomplish much the same thing with rjs, which to me, is cleaner.
you would remove the :update and :success from the form_remote_tag then
create an rjs template for your action (do_something.rjs) with the contents
of:
page.replace_html("update_div", "content") # or you could do
:partial =>
"partial_name" in place of content if you have a partial
you''d like to use
page.replace_html("some_other_div", "")
and that''s it.
references:
http://www.sergiopereira.com/articles/prototype.js.html#Reference
http://www.codyfauser.com/pages/rjs-plugin
Chris
On 3/23/06, Jon Maddox <jon@jonsthoughtsoneverything.com>
wrote:>
> maybe you could set it to be hidden or display:none.
>
> I dont know your context, so that might not work visually for your.
>
> On Mar 23, 2006, at 10:46 AM, Sebastien Hugues wrote:
>
> > Hi,
> >
> > Using form_remote_tag methode, is there a clean way to
> > directly replace the content of a given div instead of just update
> > it ?
> >
> > If I destroy the content of the div using this code:
> >
> > :success => ''$(\''mydiv'').innerHTML =
\''\'''',
> >
> > It works. But it''s not really a clean way...
> >
> > Any suggestions are very welcome..
> > Thanks.
> >
> > Seb
> > _______________________________________________
> > Rails mailing list
> > Rails@lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060323/5c664140/attachment-0001.html