JavaScript Tutorial/Style/Computed Style
Версия от 18:52, 25 мая 2010; (обсуждение)
Get Computed Style
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>
<div id="div1" class="special"></div>
<input type="button" value="Get Background Color" onclick="getBackgroundColor()" />
</body>
</html>