tags:

views:

343

answers:

2

I know that jQuery and prototype have a $.each() function for iterating over each element in an array. Does YUI offer any help with this?

+5  A: 

What keeps you from simply iterating the array?

for(var i=0; i<ary.length; i++)
  // assuming that ary[] contains objects with a DoSometing() method
  ary[i].doSomething();
Tomalak
+4  A: 

YAHOO.util.Dom has the batch function which has the following signature:

Any | Array batch( el , method , o , override )

Where el is a DOM element or an array of DOM elements, method is a function that that will be passed each element in the array as its first argument, o is an optional second argument, and override is a boolean value that determines if the scope should be window (false) or o (true)

So you could call it like this:

function setDisplay(el, display) {
    el.style.display = display;
}

YAHOO.util.Dom.batch(document.getElementsByTagName('div'), setDisplay, 'none');

Perhaps that would serve your needs.

Benry