topical media & game development

talk show tell print

professional-javascript-10-ComputedStyleExample2.htm / htm

          <title>Computed Style Example</title>
          <style type="text/css">
              div.special {
                  background-color: red;
                  height: 10px;
                  width: 10px;
                  margin: 10px;
          <script type="text/javascript">
              function getBackgroundColor() {
                  var oDiv = document.getElementById("div1");
                  alert(document.defaultView.getComputedStyle(oDiv, null).backgroundColor);
          <div id="div1" class="special"></div>
          <input type="button" value="Get Background Color" onclick="getBackgroundColor()" />
          <p><strong>Note:</strong> This example uses the DOM style methods and will fail in Internet Explorer.</p>

(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.