Prototype-element-setstyle

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

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

このメソッドは、要素のCSSスタイルプロパティを変更します。 スタイルは、プロパティとキャメル形式で指定されたプロパティと値のペアのハッシュとして渡されます。

構文

element.setStyle(styles);

戻り値

HTML要素を返します。

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

      <script>
         function setColor() {
            $('test').setStyle({
               backgroundColor: '#900',
               fontSize: '12px'
            });
         }
      </script>
   </head>

   <body">
      <p id = "test">Click the button to see the result.</p>
      <input type = "button" value = "Click" onclick = "setColor();"/>
   </body>
</html>

出力