# Toggle the caption of a link

**URL:** <https://www.ruby-forum.com/t/toggle-the-caption-of-a-link/153229>\
**Category:** Rails\
**Created:** [November 13, 2008, 5:57pm UTC](https://www.ruby-forum.com/t/toggle-the-caption-of-a-link/153229 "2008-11-13T17:57:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [November 13, 2008, 5:57pm UTC](https://www.ruby-forum.com/t/toggle-the-caption-of-a-link/153229/1 "2008-11-13T17:57:26Z")

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

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

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [November 13, 2008, 8:17pm UTC](https://www.ruby-forum.com/t/toggle-the-caption-of-a-link/153229/2 "2008-11-13T20:17:46Z")

</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…

if ($('show\_archive').readAttribute('expanded') == 'true') { ... }
## Cheers.

Robert Z.  
Zapient, LLC  
Ruby on Rails Development and Consulting

[http://www.zapient.com](http://www.zapient.com)

> **[From Java To Ruby](http://www.fromjavatoruby.com)**
>
> and everything in between...

---

<div class="post-metadata">

**Author:** ![Tarscher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/8491ac/32.png) [@Tarscher](https://www.ruby-forum.com/u/Tarscher)\
**Post date:** [November 14, 2008, 9:45am UTC](https://www.ruby-forum.com/t/toggle-the-caption-of-a-link/153229/3 "2008-11-14T09:45:51Z")

</div>

You might take a look at this:

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

Rick
