class method Element.recursivelyCollect
Element.recursivelyCollect(element, property) → [Element…]
Recursively collects elements whose relationship to element
is
specified by property
. property
has to be a property (a method
won't do!) of element
that points to a single DOM node (e.g.,
nextSibling
or parentNode
).
More information
This method is used internally by Element.ancestors
,
Element.descendants
, Element.nextSiblings
,
Element.previousSiblings
and Element.siblings
which offer really
convenient way to grab elements, so directly accessing
Element.recursivelyCollect
should seldom be needed. However, if you
are after something out of the ordinary, it is the way to go.
Note that all of Prototype's DOM traversal methods ignore text nodes and return element nodes only.
Examples
<ul id="fruits">
<li id="apples">
<ul id="list-of-apples">
<li id="golden-delicious"><p>Golden Delicious</p></li>
<li id="mutsu">Mutsu</li>
<li id="mcintosh">McIntosh</li>
<li id="ida-red">Ida Red</li>
</ul>
</li>
</ul>
And the associated JavaScript:
$('fruits').recursivelyCollect('firstChild');
// -> [li#apples, ul#list-of-apples, li#golden-delicious, p]
This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.