# Question about Element.toggle

**URL:** <https://www.ruby-forum.com/t/question-about-element-toggle/126126>\
**Category:** Rails\
**Created:** [January 15, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/question-about-element-toggle/126126 "2008-01-15T17:31:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [January 15, 2008, 5:31pm UTC](https://www.ruby-forum.com/t/question-about-element-toggle/126126/1 "2008-01-15T17:31:40Z")

</div>

I’m currently doing this:

\<%= link\_to\_function h(course.title),  
“Element.toggle(‘course#{course.id}’)” %\>

Is there a way to:

(a) Extend this so that instead of simply clicking on a title to  
toggle the element the user can click on a plus symbol that shows the  
div which also changes the plus symbol to a minus symbol. Clicking on  
the minus symbol would then hide the div and also change the minus  
symbol back to plus. I’ve seen this on quite a few websites so I  
think you know what I’m talking about 🙂

(b) Have some effect on toggling the element. I googled around and  
tried this, but it doesn’t seem to work:

\<%= link\_to\_function h(course.title),  
“Element.toggle(‘course#{course.id}’, ‘blind’)” %\>

Any ideas?

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [January 15, 2008, 11:49pm UTC](https://www.ruby-forum.com/t/question-about-element-toggle/126126/2 "2008-01-15T23:49:44Z")

</div>

Hi Vince,

The prototype Element.toggle changes the visibility of an element. I use  
scriptaculous for element effects.

You should be able to string a couple of prototype & scriptaculous  
statements together to get what you what like so…

:onclick =\> “Element.toggle(‘plus\_id’); Element.toggle(‘minus\_id’);  
Effect.appear(‘element\_id’),”

That should point in you in one possible direction.

rgds.  
matt.

Tickex - the concert, theatre, & sports search engine for tickets  
[http://www.tickex.com](http://www.tickex.com)

vince wrote:

> I’m currently doing this:
> 
> \<%= link\_to\_function h(course.title),  
> “Element.toggle(‘course#{course.id}’)” %\>
> 
> Is there a way to:
> 
> (a) Extend this so that instead of simply clicking on a title to  
> toggle the element the user can click on a plus symbol that shows the  
> div which also changes the plus symbol to a minus symbol. Clicking on  
> the minus symbol would then hide the div and also change the minus  
> symbol back to plus. I’ve seen this on quite a few websites so I  
> think you know what I’m talking about 🙂
> 
> (b) Have some effect on toggling the element. I googled around and  
> tried this, but it doesn’t seem to work:
> 
> \<%= link\_to\_function h(course.title),  
> “Element.toggle(‘course#{course.id}’, ‘blind’)” %\>
> 
> Any ideas?
