- Prototype - Home
- Prototype - Short Overview
- Prototype - Useful Features
- Prototype - Utility Methods
- Prototype - Element Object
- Prototype - Number Processing
- Prototype - Strings Processing
- Prototype - Array Processing
- Prototype - Hash processing
- Prototype - Basic Object
- Prototype - Templating
- Prototype - Enumerating
- Prototype - Event Handling
- Prototype - Form Management
- Prototype - JSON Support
- Prototype - AJAX Support
- Prototype - Expressing Ranges
- Prototype - Periodical Execution
Prototype - recursivelyCollect() Method
This method recursively collects elements whose relationship is specified by property. Property has to be a property of element that points to a single DOM node.
Syntax
element.recursivelyCollect(property);
Value of property could be any of the following −
- parentNode
- previousSibling
- nextSibling
Return Value
Returns an array of HTML elements.
Example
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var arr = $('fruits').recursivelyCollect('nextSibling');
arr.each(function(node) {
alert(node.nodeName + ': ' + node.innerHTML);
});
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<ul id = "fruits">
<li id = "apples">
<ul id = "list-of-apples">
<li id = "golden"><p>Golden</p></li>
<li id = "mutsu">Mutsu</li>
<li id = "mcintosh">McIntosh</li>
<li id = "ida-red">Ida Red</li>
</ul>
</li>
</ul>
<p>This is the paragraph</p>
<br />
<input type = "button" value = "Show Result" onclick = "showResult();"/>
</body>
</html>
Output
prototype_element_object.htm
Advertisements