Prototype-element-up

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

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

_cssRule_に一致する要素の最初の祖先(または、インデックスが指定されている場合はインデックスの先祖)を返します。

_cssRule_が指定されていない場合、すべての祖先が考慮されます。 これらの条件に一致する祖先がない場合、undefinedが返されます。

構文

element.up([cssRule][, index = 0])

戻り値

  • HTMLElementが見つかりました。
  • 要素が見つからない場合は未定義。

-element.up()とelement.up(0)は同等です。

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

      <script>
         function showResult() {
            alert( "1 : " + $('fruits').up(1).innerHTML );
            alert( "2 : " + $('mcintosh').up('li').innerHTML );
            alert( "5 : " + $('fruits').up(99) );
         }
      </script>
   </head>

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

      <ul id = "fruits">
         <li id = "apples">
            <ul>
               <li id = "golden-delicious">Golden Delicious</li>
               <li id = "mutsu" class = "yummy">Mutsu</li>
               <li id = "mcintosh" class = "yummy">McIntosh</li>
               <li id = "ida-red">Ida Red</li>
            </ul>
         </li>
      </ul>
      <br/>

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

出力