Tutorials Point


  Learn Prototype
  Prototype Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Prototype recursivelyCollect() Method


previous next AddThis Social Bookmark Button


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>

To understand it in better way you can Try it yourself.



previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names