Given this structure: <ul> <li>item1</li> <li>item2</li> <li>item3</li> </ul> Whats the best method of finding the last item in the list? 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 -~----------~----~----~----~------~----~------~--~---
If your UL has an ID, then this might do it: $(''ul_id'').down(''li:last-child'') Walter On Mar 26, 2008, at 9:51 AM, smartcookie wrote:> > Given this structure: > <ul> > <li>item1</li> > <li>item2</li> > <li>item3</li> > </ul> > > Whats the best method of finding the last item in the list? > > 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 -~----------~----~----~----~------~----~------~--~---
Give your UL an ID. For the example, I used ''moo''. alert($(''moo'').childNodes[$(''moo'').childNodes.length-1].innerHTML) You should see "item3" appear in the alert box. On Mar 26, 9:51 am, smartcookie <dpell.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Given this structure: > <ul> > <li>item1</li> > <li>item2</li> > <li>item3</li> > </ul> > > Whats the best method of finding the last item in the list? > > 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 -~----------~----~----~----~------~----~------~--~---
element[element.childNodes.length-1] wouldn''t work if lastChild is a whitespace. $$(''ul li:last-child'') on the other hand will always return element node. - kangax On Mar 26, 10:19 am, Diodeus <diod...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Give your UL an ID. For the example, I used ''moo''. > > alert($(''moo'').childNodes[$(''moo'').childNodes.length-1].innerHTML) > > You should see "item3" appear in the alert box. > > On Mar 26, 9:51 am, smartcookie <dpell.h...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Given this structure: > > <ul> > > <li>item1</li> > > <li>item2</li> > > <li>item3</li> > > </ul> > > > Whats the best method of finding the last item in the list? > > > 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 -~----------~----~----~----~------~----~------~--~---
In this case, would it return a single object, or an array of objects with a length of 1? Walter On Mar 26, 2008, at 10:42 AM, kangax wrote:> element[element.childNodes.length-1] wouldn''t work if lastChild is a > whitespace. > $$(''ul li:last-child'') on the other hand will always return element > node. > > - kangax--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Using $$ returns arrays. On Mar 26, 9:53 am, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote:> In this case, would it return a single object, or an array of objects > with a length of 1? > > Walter > > On Mar 26, 2008, at 10:42 AM, kangax wrote: > > > element[element.childNodes.length-1] wouldn''t work if lastChild is a > > whitespace. > > $$(''ul li:last-child'') on the other hand will always return element > > node. > > > - kangax--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
But you can just tack on [0] to the end of the right side of the assignment statement. On Mar 27, 6:19 pm, shadenite <shaden...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Using $$ returns arrays. > > On Mar 26, 9:53 am, Walter Lee Davis <wa...-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> wrote: > > > In this case, would it return a single object, or an array of objects > > with a length of 1? > > > Walter > > > On Mar 26, 2008, at 10:42 AM, kangax wrote: > > > > element[element.childNodes.length-1] wouldn''t work if lastChild is a > > > whitespace. > > > $$(''ul li:last-child'') on the other hand will always return element > > > node. > > > > - kangax--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---