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.
element.ancestors();
<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.
Advertisement