Walter Lee Davis wrote:
> I have a little script to do expand-o headers within a single div:
> 
> Event.observe(window,'load',function(){
>       var headers = $('test').getElementsBySelector('h3');
>       for (var i = headers.length - 1; i >= 0; i--){
>               headers[i].addClassName('fakelink');
>               headers[i].next('div').hide();
>               headers[i].observe('click',function(e){
>                       this.next('div').toggle();
>               }.bind(headers[i]));
>       };
> });
[snip]
> I'm
> wondering if someone could take a moment to show me the cool-kids way
> to do the same thing. I am guessing it is probably some one-word magic
> like 'each' or something like that...

Event.observe(window,'load',function(){
    $A($('test').getElementsBySelector('h3')).each(function(header) {
        header.addClassName('fakelink');
        header.next('div').hide();
        header.observe('click',function(e){
             this.next('div').toggle();
        }.bind(header));
    };
});

-- 
Michael Peters
Developer
Plus Three, LP


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