-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdom.html
79 lines (79 loc) · 3.04 KB
/
dom.html
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<html>
<head>
<title>DOM Demo</title>
<style>
h1 {
text-align: center;
}
button {
border: 1px solid black;
text-size: 20px;
}
div {
border: 3px solid black;
width: 200px;
height: 200px;
text-size: 20px;
}
input {
border: 1px solid black;
text-size: 20px;
}
</style>
</head>
<body>
<h1>DOM Demo</h1>
<br><br>
<h3>.onclick</h3>
<div id="one" style="background-color:lightblue;">Click on this div to make it RED!</div>
<br>
<h3>.onmouseover and .onmouseout</h3>
<div id="two" style="background-color:lightgreen;">Hover over this div to make it purple, and take your mouse off to see it become green again!</div>
<h3>.onkeyup</h3>
<p>Enter something in the textbox, and see the text to the right of it change!</p>
<input id="three" type="textbox"></input> <span id="cone">Watch me change!</span>
<h3>.onchange</h3>
<p>Enter something in the textbox, and then click away to see the text to the right of it change!</p>
<input id="four" type="textbox"></input> <span id="ctwo">Watch me change!</span>
<h3>.onfocus and .onblur</h3>
<p>Click on the textbox, and then click away from the textbox, and see how the text in the textbox changes!</p>
<input id="five" type="textbox" value="Hello world!"></input>
<script>
var one = document.getElementById("one");
var two = document.getElementById("two");
var three = document.getElementById("three");
var four = document.getElementById("four");
var five = document.getElementById("five");
var cone = document.getElementById("cone");
var ctwo = document.getElementById("ctwo");
one.onclick = function() {
if (one.style.backgroundColor == "lightblue") {
one.style.backgroundColor = "red";
one.innerText = "Click on this div to make it BLUE!";
}
else {
one.style.backgroundColor = "lightblue";
one.innerText = "Click on this div to make it RED!";
}
}
two.onmousemove = function() {
two.style.backgroundColor = "purple";
}
two.onmouseout = function() {
two.style.backgroundColor = "lightgreen";
}
three.onkeyup = function() {
cone.innerText = three.value;
}
four.onchange = function() {
ctwo.innerText = four.value;
}
five.onfocus = function() {
five.value = "Goodbye world!";
}
five.onblur = function() {
five.value = "Hello world!";
}
</script>
</body>
</html>