Forum: Ruby on Rails ajax replace div

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Sebastien H. (Guest)
on 2006-03-23 17:49
(Received via mailing list)

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..

Jon Maddox (Guest)
on 2006-03-23 18:08
(Received via mailing list)
maybe you could set it to be hidden  or display:none.

I dont know your context, so that might not work visually for your.
Chris H. (Guest)
on 2006-03-23 19:02
(Received via mailing list)
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')

// removes element from document


<%= 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

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

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
page.replace_html("some_other_div", "")

and that's it.


This topic is locked and can not be replied to.