Prototype-element-childelements

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

プロトタイプ-childElements()メソッド

要素のすべての子を収集し、それらを拡張要素の配列として返します。

インデックス0は、要素の最上位の子を指します。

構文

element.childElements();

戻り値

HTML要素の配列。

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>

      <script>
         function showElements() {
            var arr =  $('father').childElements();
            arr.each(function(node) {
               alert(node.nodeName + ': ' + node.innerHTML);
            });
         }
      </script>
   </head>

   <body>
      <div id = "father">
         <p id = "kid1">This is first paragraph</p>
         <p id = "kid2">This is second paragraph</p>
      </div>
      <br/>

      <input type = "button" value = "showElements" onclick = "showElements();"/>
   </body>
</html>

出力