Prototype - descendants() 方法



此方法收集元素的所有後代,並將其作為擴充套件元素陣列返回。

請注意,Prototype 的所有 DOM 遍歷方法都將忽略文字節點,只返回元素節點。

語法

element.descendants() ;

返回值

HTML 元素陣列。

示例

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showElements() {
            var arr = $('father').descendants();
            arr.each(function(node) {
               alert(node.nodeName + ': ' + node.innerHTML);
            });
         }
      </script>
   </head>
   
   <body>
      <p>Click descendants button to see the result.</p>
      <div id = "father">
         <p id = "kid">This is first paragraph</p>
      </div>
      <br />
      
      <input type = "button" value = "descendants" onclick = "showElements();"/>
   </body>
</html>

輸出

prototype_element_object.htm
廣告