JavaScript Tutorial/Style/Computed Style
Get Computed Style
<source lang="javascript">
This example uses the DOM style methods and will fail in Internet Explorer. <html>
<head> <title>Computed Style Example</title> <style type="text/css"> div.special { background-color: red; } </style> <script type="text/javascript"> function getBackgroundColor() { var oDiv = document.getElementById("div1"); alert(document.defaultView.getComputedStyle(oDiv, null).backgroundColor); } </script> </head> <body>
<input type="button" value="Get Background Color" onclick="getBackgroundColor()" /> </body>
</html></source>