Prototype-element-firstdescendant

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

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

このメソッドは、要素である最初の子を返します。 これは、任意のノードを返す_firstChild_ DOMプロパティとは対照的です。

構文

element.firstDescendant();

戻り値

HTML要素を返します。

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

      <script>
         function showResult() {
            desc = $('grandfather').firstDescendant();
            alert("First Descendant is : " + desc.nodeName + ':' + desc.innerHTML );
            child = $('grandfather').firstChild;
            alert("First Child is : " + child.toString() );
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>

      <div id = "grandfather">This is grand father
         <div id = "father"> This is father.
            <div id = "kid">This is kid</div>
         </div>
      </div>
      <br/>

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

出力