lastDescendant enhancement

0 views
Skip to first unread message

Varga-Háli Dániel

unread,
Jan 11, 2009, 9:02:28 AM1/11/09
to prototy...@googlegroups.com
Hello,

I have added a simple enhancement to the prototype lib (v1.6.0) which
can be used to get the last childnode of element:

lastDescendant: function(element) {
var descs = $(element).descendants();
var iterator = 1;
element = descs[descs.length-iterator];
while(element && element.nodeType != 1 && iterator <= descs.length) {
iterator++;
element = descs[descs.length-iterator];
}
return $(element);
}

With syntax highlighting it is available here: http://pastebin.com/f5918ff36

I hope some of you will find it useful. :)

Regards,
Daniel Varga, Hungary

Diego Perini

unread,
Jan 11, 2009, 11:13:31 AM1/11/09
to Prototype: Core
Daniel,
this is a copy of current Prototype "firstDescendant" modified to fit.

lastDescendant: function(element) {
element = $(element).lastChild;
while (element && element.nodeType != 1) element =
element.previousSibling;
return $(element);
},

Isn't this what you need ?

Diego

Varga-Háli Dániel

unread,
Jan 11, 2009, 1:39:58 PM1/11/09
to prototy...@googlegroups.com
Ohh yes... This is pretty much the same with a lot less code and in a
more elegant way :)

Thanx Diego :)

2009/1/11 Diego Perini <diego....@gmail.com>:
Reply all
Reply to author
Forward
0 new messages