Expanding on DJ's answer (which has a couple of errors, but he was on
his phone!), more generally, if you can get the elements into an
array, you can use Enumerable#invoke to call the same method on
each of the elements. So for instance, if you used DJ's suggestion
and gave them all the same class, it becomes:
Tidy, eh? Now, if you need to do it with a disparate set of elements,
you can always use an array literal:
If you *really* want to squeeze down the character count, you can use
$w to create the array:
$w (note that it's lower case; it's the only lower case one of the $
functions) splits a string into an array on whitespace. Adds a tiny
bit of overhead and saves a few keystrokes.
There's more about looping arrays in the unofficial wiki. It is
also well worth your time to take an hour and read through the
Prototype API front to back. It literally takes an hour or so, and
it pays you back very very quickly.
tj / crowder software / com
Independent Software Engineer, consulting services available
On Aug 7, 6:59 pm, trope <jtrope...@gmail.com> wrote:
> I have some code that appears to be a prime candidate for a loop.
> How could I wrap this up in one neat little function???
> /* Hide previous errors */
> Thank you.
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to email@example.com
To unsubscribe from this group, send email to
For more options, visit this group at