Prototype-element-visible

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

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

このメソッドは、要素が表示されているかどうか、つまり、インラインスタイルプロパティが「display:none;」に設定されているかどうかを示すブール値を返します。

-CSSスタイルシートを介して適用されたスタイルは考慮されません。 これはプロトタイプの制限ではなく、CSSの制限であることに注意してください。

構文

element.visible();

戻り値

HTML要素。

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

      <script>
         function showResult() {
            if( $('visible').visible() ) {
               alert("$('visible').visible() returns true" );
            } else {
               alert("$('visible').visible() returns false" );
            }

            if( $('hidden').visible() ) {
               alert("$('hidden').visible() returns true" );
            } else {
               alert("$('hidden').visible() returns false" );
            }
         }
      </script>
   </head>

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

      <div id = "visible" style = "display:block;">
         This is visible division
      </div>

      <div id = "hidden" style = "display: none;">
         This is hidden division
      </div>

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

出力