topical media & game development

talk show tell print

professional-javascript-10-AccessingStyleSheetsExample4.htm / htm



  <html>
      <head>
          <title>Accessing Style Sheets Example</title>
          <style type="text/css">
              div.special {
                  background-color: red;
                  height: 10px;
                  width: 10px;
                  margin: 10px;
              }
          </style>
          <script type="text/javascript">
              function changeBackgroundColor() {
                  var oDiv = document.getElementById("div1");
                  oDiv.style.backgroundColor = "blue";
              }
          </script>
      </head>
      <body>
          <div id="div1" class="special"></div>
          <div id="div2" class="special"></div>
          <div id="div3" class="special"></div>
          
          <input type="button" value="Change Background Color" onclick="changeBackgroundColor()" />
      </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.