Prototype-element-empty

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

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

出力