On Sep 10, 10:20 am, Matt Foster <[EMAIL PROTECTED]> wrote:
> firstDescendant is a convienence function for referencing the
> "firstChild" where its an immediate descendant of the element.  At
> first I thought you could just bust out with ele.descendants().last()
> but in researching this idea it would potentially give you unexpected
> results.  As descendants()  grabs all children and grandchildren the
> last object on that array could very well be a deeply nested element
> and not particularly the lastChild element reference that you were
> looking for.  If this method is something you would really value you
> could simply add it yourself using the Element.addMethods method, it
> might look something like this.
>
> Element.addMethods({
>   lastDescendant: function(element) {
>     element = $(element).lastChild;
>     while (element && element.nodeType != 1) element =
> element.previousSibling;
>     return $(element);
>   }
>
> });

A less performant, but shorter version would be:

$(element).childElements().last();

--
kangax
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to