Prototype - ancestors() 方法
此方法收集元素的所有祖先并将它们作为扩展元素数组返回。
请记住,body 和 html 元素也将包括在内。
语法
element.ancestors();
返回值
HTML 元素数组。
示例
<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>