Prototype-element-descendants

提供:Dev Guides
移動先:案内検索

プロトタイプ-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>

出力