You could shrink it (and speed it up, fractionally) even more.   
Element.hide returns the hidden element as a reference, so bind your  
observer to the div element...

Event.observe(window, "load", function() {
     $$("#test h3").each(function(element) {
        element.addClassName("fakelink");
        element.observe("click", function() {this.toggle();}.bind 
( element.next("div").hide() ));
     });
});

addClassName returns the element too, so you could chain even further  
if the fancy struck. It sacrifices readability though, for negligible  
gain.

Event.observe(window, "load", function() {
     $$("#test h3").each(function(element) {
        element.addClassName("fakelink").observe("click", function()  
{this.toggle();}.bind( element.next("div").hide() ));
     });
});


TAG

On Apr 24, 2007, at 6:46 PM, David Dashifen Kees wrote:

>
> This would be another option in addition to Michael's:
>
> Event.observe(window, "load", function() {
>     $$("#test h3").each(function(element) {
>        element.addClassName("fakelink");
>        element.next("div").hide();
>        element.observe("click", function() { this.next("div").toggle 
> ();
> }.bind(element));
>     });
> });


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to