-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStyleObjectExample.htm
executable file
·35 lines (29 loc) · 1.15 KB
/
StyleObjectExample.htm
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
31
32
33
34
35
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Style Object Example</title>
</head>
<body>
<div id="myDiv" style="background-color: blue; width: 10px; height: 25px"></div>
<input type="button" value="Get Styles" onclick="getStyles()" />
<input type="button" value="Change Styles" onclick="changeStyles()" />
<script type="text/javascript">
function changeStyles(){
var myDiv = document.getElementById("myDiv");
//set the background color
myDiv.style.backgroundColor = "red";
//change the dimensions
myDiv.style.width = "100px";
myDiv.style.height = "200px";
//assign a border
myDiv.style.border = "1px solid black";
}
function getStyles(){
var myDiv = document.getElementById("myDiv");
alert(myDiv.style.backgroundColor);
alert(myDiv.style.width);
alert(myDiv.style.height);
}
</script>
</body>
</html>