ancestors

ancestors(element) -> [HTMLElement...]

Collects all of element’s ancestors and returns them as an array of extended elements.

The returned array’s first element is element’s direct ancestor (its parentNode), the second one is its grandparent and so on until the html element is reached. html will always be the last member of the array… unless you are looking for its ancestors obviously. But you wouldn’t do that, would you ?

Note that all of Prototype’s DOM traversal methods ignore text nodes and return element nodes only.

Examples


<html>
[…]
  <body>
    <div id="father">
      <div id="kid">
      </div>
    </div>
  </body>
</html>

$('kid').ancestors();
// -> [div#father, body, html]  // Keep in mind that 
// the `body` and `html` elements will also be included!

document.getElementsByTagName('html')[0].ancestors();
// -> []