# toggle the caption of a link

**URL:** <https://discuss.rubyonrails.org/t/toggle-the-caption-of-a-link/36327>\
**Category:** rubyonrails-talk\
**Created:** [November 13, 2008, 4:56pm UTC](https://discuss.rubyonrails.org/t/toggle-the-caption-of-a-link/36327 "2008-11-13T16:56:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher1](https://avatars.discourse-cdn.com/v4/letter/t/77aa72/32.png) [@Tarscher1](https://discuss.rubyonrails.org/u/Tarscher1)\
**Post date:** [November 13, 2008, 4:56pm UTC](https://discuss.rubyonrails.org/t/toggle-the-caption-of-a-link/36327/1 "2008-11-13T16:56:32Z")

</div>

hi all,

I'm trying to toggle the caption of a link between show archive and hide archive? Everytime a user clicks the link the caption should change.

I tried but this simply doesn't work.

Someone can help me out?

Thanks Stijn

&nbsp;&nbsp;\<div id="show\_archive"\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= link\_to\_function "Show archive" do |page| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if page['show\_archive'].value == "Show archive" &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page['show\_archive'].replace\_html("Hide archive") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;page['show\_archive'].replace\_html("Show archive") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;end %\> &nbsp;&nbsp;\</div\>

---

<div class="post-metadata">

**Author:** ![Robert\_Zotter](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@Robert\_Zotter](https://discuss.rubyonrails.org/u/Robert_Zotter)\
**Post date:** [November 13, 2008, 7:16pm UTC](https://discuss.rubyonrails.org/t/toggle-the-caption-of-a-link/36327/2 "2008-11-13T19:16:58Z")

</div>

Tarscher.

First off you should download and install Firebug for firefox to help you debug any javascript errors you may be having. [http://getfirebug.com/](http://getfirebug.com/)

The problem you are having is because you are calling a non-existent method, value(), on the div element. There is also no RJS method called value: [http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html)

You should probably just use plain ol javascript for this one so you can check the current innerHTML of the div.

ie. if ($('show\_archive').innerHTML == 'Show archive') { ... }

Or you could set some arbitrary attribute on the div and check it

ie... \<div id='show\_archive' expanded='true' %\>\</div\> if ($('show\_archive').readAttribute('expanded') == 'true') { ... }

Cheers.

---

<div class="post-metadata">

**Author:** ![Rick3](https://avatars.discourse-cdn.com/v4/letter/r/ecb155/32.png) [@Rick3](https://discuss.rubyonrails.org/u/Rick3)\
**Post date:** [November 14, 2008, 8:45am UTC](https://discuss.rubyonrails.org/t/toggle-the-caption-of-a-link/36327/3 "2008-11-14T08:45:04Z")

</div>

You might take a look at this:

[http://wiki.rubyonrails.org/rails/pages/HowtoUseElement](http://wiki.rubyonrails.org/rails/pages/HowtoUseElement)

Rick
