-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputedStylesExample.htm
More file actions
executable file
·30 lines (30 loc) · 1.08 KB
/
Copy pathComputedStylesExample.htm
File metadata and controls
executable file
·30 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!DOCTYPE html>
<html>
<head>
<title>Computed Styles Example</title>
<style type="text/css">
#myDiv {
background-color: blue;
width: 100px;
height: 200px;
}
</style>
<script type="text/javascript">
function showComputedStyles(){
var myDiv = document.getElementById("myDiv");
var computedStyle = document.defaultView.getComputedStyle(myDiv, null);
alert(computedStyle.backgroundColor); //"red"
alert(computedStyle.width); //"100px"
alert(computedStyle.height); //"200px"
alert(computedStyle.border); //"1px solid black"
alert(computedStyle.borderLeftWidth); //"1px"
alert(computedStyle.visibility);
}
</script>
</head>
<body>
<div id="myDiv" style="background-color: red; border: 1px solid black"></div>
<input type="button" value="Show Computed Styles" onclick="showComputedStyles()">
<p>(This example won't work in IE < 9.)</p>
</body>
</html>