On May 21, 5:06 am, Alex Duffield <[EMAIL PROTECTED]> wrote:
> I have a situation where I need to get the first class name of an
> element.
>
> Element.ClassNames() returns an object not an array...
>
> Object.values() will turn it into an array, but the API Docs say that
> the order of the resulting array is browser-dependent.. So for my use
> is no good...
>
> So I am using:
>
> el.className.split(" ").first();
Why not:
el.className.split(" ")[0];
> Can any one see any problems that I might encounter doing it this way??
A space is the designated separator between class names and leading,
trailing and multiple spaces are supposed to be ignored. However, you
can't guarantee that a particular browser will return a class
attribute properly formatted (e.g. IE). The above will fail if the
className is returned as " Fred".
So in practice you should trim spaces from the ends, then ensure there
are no multiple internal extra spaces. Or use a function to do it for
you.
--
Rob
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---