- Prototype Tutorial
- 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 Useful Resources
- Prototype - Quick Guide
- Prototype - Useful Resources
- Prototype - Discussion
Prototype - ancestors() Method
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>
Output
prototype_element_object.htm
Advertisements