Prototype-element-empty

提供:Dev Guides
2020年6月23日 (火) 02:07時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

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

このメソッドは、要素が空かどうか(つまり、空白のみが含まれているかどうか)をテストします。

構文

element.empty;

戻り値

その要素が空の要素であることがわかると、trueを返します。それ以外の場合はfalseを返します。

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

      <script>
         function showResult() {
            if($('wallet').empty() ) {
               alert( "Wallet is empty " );
            }
            if($('cart').empty() ) {
               alert( "Cart is full" );
            }
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      <div id = "wallet">     </div>
      <div id = "cart">full!</div>
      <br/>
      <input type = "button" value = "showResult" onclick = "showResult();"/>
   </body>
</html>

この例では-

$('wallet').empty();
//-> true
$('cart').empty();
//-> false

出力