On Apr 2, 5:57 pm, basti <bastian.friedr...@am-soft.de> wrote:
> Good morning,
>
> I wanted to use the method "getElementsByClassName" by prototype to
> retrieve an array of objects. Using my Firefox 3.0.7 on Windows XP
> alert told me that the returned value by this method is a Nodelist,
> which I couldn't iterate using prototypes each-method for arrays.
You can convert the retuned NodeList to an array using $A(), or if you
want to be a little clever you can test the returned object's
constructor and only convert non-Arrays:
var nodes = document.getElementsByClassName('foo');
if (nodes.constructor != Array) {
nodes = $A(nodes);
}
The host getElementsByClassName is likely much faster in general than
a native javascript replacement.
HTML 5 includes a selector API that will provide host methods for a
much greater range of selectors, they should offer significant speed
enhancements over current native selector APIs.
<URL: http://www.w3.org/TR/selectors-api/ >
--
Rob
--~--~---------~--~----~------------~-------~--~----~
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 prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---