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(); Can any one see any problems that I might encounter doing it this way?? Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
You can do this: $(''myDiv'').classNames().toArray().first() with the usual caveats about extended elements (see: http://www.prototypejs.org/learn/extensions ) On 5/20/07, Alex Duffield <Alex-GLL9njBnHiGqPKKiFzS5XxZCeNDtXRbv@public.gmane.org> 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(); > > Can any one see any problems that I might encounter doing it this way?? > > > Thanks. > > > > > > > > >-- Jesse E.I. Farmer e: jesse-h8Qh2m8E5SHQT0dZR+AlfA@public.gmane.org w: http://20bits.com --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On May 21, 5:06 am, Alex Duffield <A...-GLL9njBnHiGqPKKiFzS5XxZCeNDtXRbv@public.gmane.org> 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 rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---