# Simple RJS question--toggling the text of a link\_to\_function link

**URL:** <https://www.ruby-forum.com/t/simple-rjs-question-toggling-the-text-of-a-link-to-function-link/174112>\
**Category:** Rails\
**Created:** [August 20, 2009, 11:45pm UTC](https://www.ruby-forum.com/t/simple-rjs-question-toggling-the-text-of-a-link-to-function-link/174112 "2009-08-20T23:45:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpardee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rpardee](https://www.ruby-forum.com/u/rpardee)\
**Post date:** [August 20, 2009, 11:45pm UTC](https://www.ruby-forum.com/t/simple-rjs-question-toggling-the-text-of-a-link-to-function-link/174112/1 "2009-08-20T23:45:32Z")

</div>

Hey All,

I’m dabbling in a little DHTML to show/hide a fieldset on a page, w/  
the following:

\<%=  
link\_to\_function(“Show People”, nil, :id =\> “more\_link”) do |page|  
page.visual\_effect(:toggle\_appear, “organization-people”)  
page.replace\_html(“more\_link”, “Hide People”)  
end  
%\>

This works very nicely, except for one thing–when the page loads, the  
link attached to the resulting jscript function is “Show People”. The  
first time I click it changes to “Hide People” & the fieldset appears–  
all very nice. My problem is that I don’t know how to change the link  
text back to “Show People” once the user clicks a second time. The  
link always _does_ what I want–showing or hiding as appropriate, but  
it only _says_ what I want for the first two clicks.

Is there a way to find out what the current link contains so I can  
make that call to replace\_html conditional?

Many thanks!

-Roy

---

<div class="post-metadata">

**Author:** ![rpardee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rpardee](https://www.ruby-forum.com/u/rpardee)\
**Post date:** [August 24, 2009, 5:55pm UTC](https://www.ruby-forum.com/t/simple-rjs-question-toggling-the-text-of-a-link-to-function-link/174112/2 "2009-08-24T17:55:25Z")

</div>

Nobody has advice for me on this? ☹

---

<div class="post-metadata">

**Author:** ![rpardee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rpardee](https://www.ruby-forum.com/u/rpardee)\
**Post date:** [August 24, 2009, 6:53pm UTC](https://www.ruby-forum.com/t/simple-rjs-question-toggling-the-text-of-a-link-to-function-link/174112/3 "2009-08-24T18:53:57Z")

</div>

Hi Roy,

You should post your javascript function if you want help with modifying  
it. That’s where the modification of the link text would ‘normally’  
happen.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![rpardee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rpardee](https://www.ruby-forum.com/u/rpardee)\
**Post date:** [August 24, 2009, 7:24pm UTC](https://www.ruby-forum.com/t/simple-rjs-question-toggling-the-text-of-a-link-to-function-link/174112/4 "2009-08-24T19:24:24Z")

</div>

On Aug 24, 4:17 pm, Roy P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Nobody has advice for me on this? ☹

you basically need to write some raw javascript for this ( if  
(‘something’.innerHTML == …)) and either mash that together with the  
rjs stuff using \<\< or just write the whole thing in javascript and  
forget about the rjs bits

Fred

---

<div class="post-metadata">

**Author:** ![rpardee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e47c2d/32.png) [@rpardee](https://www.ruby-forum.com/u/rpardee)\
**Post date:** [August 25, 2009, 3:14pm UTC](https://www.ruby-forum.com/t/simple-rjs-question-toggling-the-text-of-a-link-to-function-link/174112/5 "2009-08-25T15:14:38Z")

</div>

You mean I would have to sacrifice my carefully crafted complete  
ignorance of javascript? Bummer. 😉

Thanks guys. Perhaps today _is_ a good day to start reading up on  
javascript.

Thanks!

-Roy

On Aug 24, 10:00 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
