Tutorials Point


  Learn Prototype
  Prototype Resources
  Selected Reading

© 2011 TutorialsPoint.COM


  Home     References     Discussion Forums     About TP  

Prototype ancestors() Method


previous next AddThis Social Bookmark Button


This method collects all of element's ancestors and returns them as an array of extended elements.

Keep in mind that the body and html elements will also be included.

Syntax:

element.ancestors();

Return Value:

  • An array of HTML elements.

Example:

<html>
<head>
<title>Prototype examples</title>
<script type="text/javascript" 
   src="/javascript/prototype.js">
</script>
<script>


function showElements(){
   var arr =  $('kid').ancestors();
   arr.each(function(node){
      alert(node.nodeName + ': ' + node.innerHTML);
   });

}

</script>
</head>

<body>
   <div id="father">
      <p id="kid">This is first paragraph</p>
   </div>

   <br />
   <input type="button" value="showElements"
             onclick="showElements();"/>

</body>
</html>

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



previous next Printer Friendly



  

Advertisement

Online Image Processing

Indian Baby Names