# Toggle appear starts hidden?

**URL:** <https://www.ruby-forum.com/t/toggle-appear-starts-hidden/185914>\
**Category:** Rails\
**Created:** [March 29, 2010, 8:06am UTC](https://www.ruby-forum.com/t/toggle-appear-starts-hidden/185914 "2010-03-29T08:06:58Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [March 29, 2010, 8:06am UTC](https://www.ruby-forum.com/t/toggle-appear-starts-hidden/185914/1 "2010-03-29T08:06:58Z")

</div>

This definitely works:

\<%= button\_to\_remote “Test”, :complete =\>  
visual\_effect( :toggle\_appear, “toggle\_appear” ) %\>

 yada yada yada 

To toggle content off -\> content on, etc.

But is there any way to have the initial content hidden?

Many TIA,  
Craig

---

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [March 29, 2010, 8:12am UTC](https://www.ruby-forum.com/t/toggle-appear-starts-hidden/185914/2 "2010-03-29T08:12:14Z")

</div>

try

 yada yada yada

---

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [March 29, 2010, 8:26am UTC](https://www.ruby-forum.com/t/toggle-appear-starts-hidden/185914/3 "2010-03-29T08:26:17Z")

</div>

i never tried that, but i think you could iterate the elements with the  
class name like:

$$(’.clazz’).each(function(e) {  
e.toggle();  
})

or else, you could write your own function, for example:  
function toggle\_all() {  
toggle1();  
toggle2();  
…  
}

function toggle1() {  
…  
}

function toggle2() {  
…  
}

---

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [March 29, 2010, 8:16am UTC](https://www.ruby-forum.com/t/toggle-appear-starts-hidden/185914/4 "2010-03-29T08:16:55Z")

</div>

On Mar 28, 11:10 pm, Yong Gu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> try
> 
> yada yada yada

Thanks, Yong!

One other question: is it possible to have multiple divs toggling on/  
off at the same time? I tried changing “id” to “class”, and then it  
simply wouldn’t toggle.

Many TIA again,  
Craig

---

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [March 29, 2010, 8:41am UTC](https://www.ruby-forum.com/t/toggle-appear-starts-hidden/185914/5 "2010-03-29T08:41:30Z")

</div>

On Mar 28, 11:24 pm, Yong Gu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i never tried that, but i think you could iterate the elements with the  
> class name like:  
> …

Thanks–I was hoping that I could chain the events within/around the  
visual\_effect method–any idea if that’s possible in this framework?

Many TIA again,  
Craig

---

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [March 29, 2010, 4:06pm UTC](https://www.ruby-forum.com/t/toggle-appear-starts-hidden/185914/6 "2010-03-29T16:06:22Z")

</div>

On Mar 28, 11:49 pm, Yong Gu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> try \<%= button\_to\_remote “Test”, :complete =\> “toggle\_all();” %\>  
> …

Thanks! I discovered this morning that + is defined for complete, so  
that

\<%= button\_to\_remote “Test”, :complete =\>  
visual\_effect( :toggle\_appear, “toggle\_appear” ) +  
visual\_effect( :toggle\_appear, “toggle\_appear2” ) %\>

works, which is pretty cool. It’s arguably less elegant than your  
solution, but it keeps it purely railsy 🙂

Again, many thanks!

---

<div class="post-metadata">

**Author:** ![Dudebot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e495f1/32.png) [@Dudebot](https://www.ruby-forum.com/u/Dudebot)\
**Post date:** [March 29, 2010, 8:50am UTC](https://www.ruby-forum.com/t/toggle-appear-starts-hidden/185914/7 "2010-03-29T08:50:52Z")

</div>

yes, of course

try \<%= button\_to\_remote “Test”, :complete =\> “toggle\_all();” %\>

which toggle\_all is your own defined javascript funciton or use  
$(’.clazz’).each(function(e) { e.toggle()} ) directly instead of  
toggle\_all()

in fact, the value of parameter :complete is a javascript function , and  
visual\_effect generate a function by using prototype.js. So you could

use any javascript function as you wish.
