Prototype-element-toggle

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

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

このメソッドは、要素の可視性を切り替えます。

-Element.toggleは、CSSスタイルシートを介して非表示の要素を表示できません。 これはプロトタイプの制限ではなく、CSS表示プロパティの動作の結果であることに注意してください。

構文

element.toggle();

戻り値

HTML要素を返します。

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

      <script>
         function toggleMsg() {
            $('test').toggle();
         }
      </script>
   </head>

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

      <div id = "test" style = "display:inline;">
         <p>This message will toggle when you click the button</p>
      </div>
      <br/>

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

出力