Hiya Johan.
The reason your code is not working is because you are passing it a
single (one) anchor element reference.
So it appends it to each fieldset, which would remove it from the
previously set fieldset.
If you did:
$$('form fieldset').invoke('insert', '<a href="#">advanced</
a>').pluck('lastChild').invoke('observe', 'click', function(event) {
this.up('form').toggleClassName('simple');
});
It would work because you are creating a new anchor element for each
iteration.
This may clean but it does require 3 iterations instead of 1 (note the
2 uses of invoke and 1 pluck).
this one uses only 1 iteration:
$$('form fieldset').each(function(element){
element.insert( new Element('a',{ href: '#' })
.update('advanced')
.observe('click', function(event) {
this.up('form').toggleClassName('simple')
)
});
OR (my fav)
$$('form fieldset').each(function(element){
element.insert('<a href="#">advanced</
a>').lastChild.observe('click', function(event) {
this.up('form').toggleClassName('simple')
})
});
-JDD
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---