Hide & Show div (Element.toggle)

I have 2 divs:

<div id="div1"> <%= link_to_function("Show div2",
"Element.toggle('div2')") %> </div>
<div id="div2"> <%= link_to_function("Show div1",
"Element.toggle('div1')") %> </div>

I want, when I click link: "Show div2" it hide div1 and show div2,
when i click "Show div1" it hide div2 and show div1

How can i do it?

I have 2 divs:

<div id="div1"> <%= link_to_function("Show div2",
"Element.toggle('div2')") %> </div>
<div id="div2"> <%= link_to_function("Show div1",
"Element.toggle('div1')") %> </div>

I want, when I click link: "Show div2" it hide div1 and show div2,
when i click "Show div1" it hide div2 and show div1

How can i do it?

just make your call to link_to function toggle both divs - you aren't
limited to a single javascript statement.

Fred

Frederick Cheung wrote:

How can i do it?

just make your call to link_to function toggle both divs - you aren't
limited to a single javascript statement.

Fred

I can't make it work :frowning:

By default div2 is hidden:

<div id="div1">
  <%= link_to_function("Show div2", "Element.toggle('div1', 'div2)") %>
</div>
<div id="div2" style="display:none;">
  <%= link_to_function("Show div1", "Element.toggle('div1', 'div2')") %>
</div>

Frederick Cheung wrote:

How can i do it?

just make your call to link_to function toggle both divs - you aren't
limited to a single javascript statement.

Fred

I can't make it work :frowning:

Just make two calls to Element.toggle

Fred

Sample:

Element.toggle(‘div1’); Element.toggle(‘div2’);