-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdom-try-out.html
222 lines (173 loc) · 6.22 KB
/
dom-try-out.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<html>
<head>
<title>trying out new thing in dom</title>
<style>
#container {
width: 400px;
height: 400px;
position: relative;
background: yellow;
}
#animate {
width: 50px;
height: 50px;
position: absolute;
background: red;
}
#myDiv1, #myDiv2 {
background-color: coral;
padding: 50px;
}
#myP1, #myP2 {
background-color: white;
font-size: 20px;
border: 1px solid;
padding: 20px;
}
#myDIV {
background-color: coral;
border: 1px solid;
padding: 50px;
color: white;
font-size: 20px;
}
</style>
</head>
<body onload="checkCookies()">
<h2>My First JavaScript Animation</h2>
<p><button onclick="myMove()">Click Me</button></p>
<div id ="container">
<div id ="animate"></div>
</div>
<h1 onclick="changeText(this)">Click on this text!</h1>
<button onclick="displayDate()">Try it</button>
<button id="myBtn">Try it</button>
<p id="demo"></p>
Enter your name: <input type="text" id="fname" onchange="myfunction()">
<div onmouseover="mOver(this)" onmouseout="mOut(this)" style="background-color:#D94A38;width:120px;height:20px;padding:40px;">
Mouse Over Me
</div>
<div onmousedown="mDown(this)" onmouseup="mUp(this)"style="background-color:#D94A38;width:90px;height:20px;padding:40px;">
Click Me
</div>
<p id="sky"></p>
Enter your name: <input type="text" onfocus="myFunction(this)">
<h1 onmouseover="style.color='red'"
onmouseout="style.color='black'">
Mouse over this text
</h1>
<div id="myDiv1">
<h2>Bubbling:</h2>
<p id="myP1">Click me!</p>
</div><br>
<div id="myDiv2">
<h2>Capturing:</h2>
<p id="myP2">Click me!</p>
</div>
<div id="myDIV">
<p>This div element has an onmousemove event handler that displays a random number every time you move your mouse inside this orange field.</p>
<p>Click the button to remove the div's event handler.</p>
<button onclick="removeHandler()" id="myBtun">Remove</button>
</div>
<p id="afric"></p>
</body>
<script>
function myfunction() {
var x = document.getElementById("fname");
x.value = x.value.toUpperCase();
}
//function mymessage() {
//alert("This message was triggered from the onload event");
//}
function checkCookies() {
var text = "";
if (navigator.cookieEnabled == true) {
text = "Cookies are enabled.";
} else {
text = "Cookies are not enabled.";
}
document.getElementById("demo").innerHTML = text;
}
function myMove() {
let elem = document.getElementById("animate");
let pos = 0;
let id = setInterval(frame, 5);
function frame() {
if (pos == 350) {
clearInterval(id);
} else {
pos++;
elem.style.top = pos + 'px';
elem.style.left = pos + 'px';
}
}
}
function changeText(id) {
id.innerHTML = "Ooops!";
}
let x = document.getElementById("myBtn");
x.addEventListener("mouseover", myifunction);
x.addEventListener("click", mySecondFunction);
x.addEventListener("mouseout", myThirdFunction);
function myifunction() {
document.getElementById("demo").innerHTML += "Moused over!<br>";
}
function mySecondFunction() {
document.getElementById("demo").innerHTML += "Clicked!<br>";
}
function myThirdFunction() {
document.getElementById("demo").innerHTML += "Moused out!<br>";
}
let p1 = 5;
let p2 = 7;
document.getElementById("myBtn").addEventListener("click", function() {
myunction(p1, p2);
});
function myunction(a, b) {
let result = a * b;
document.getElementById("demo").innerHTML = result;
}
window.addEventListener("resize", function(){
document.getElementById("myBtn").innerHTML = Math.random(4);
});
function displayDate() {
document.getElementById("demo").innerHTML = Date();
}
function mOver(obj) {
obj.innerHTML = "Thank You"
}
function mOut(obj) {
obj.innerHTML = "Mouse Over Me"
}
function mDown(obj) {
obj.style.backgroundColor = "#1ec5e5";
obj.innerHTML = "Release Me";
}
function mUp(obj) {
obj.style.backgroundColor="#D94A38";
obj.innerHTML="Thank You";
}
function myFunction(x) {
x.style.background = "yellow";
}
document.getElementById("myP1").addEventListener("click", function() {
alert("You clicked the white element!");
}, false);
document.getElementById("myDiv1").addEventListener("click", function() {
alert("You clicked the orange element!");
}, false);
document.getElementById("myP2").addEventListener("click", function() {
alert("You clicked the white element!");
}, true);
document.getElementById("myDiv2").addEventListener("click", function() {
alert("You clicked the orange element!");
}, true);
document.getElementById("myDIV").addEventListener("mousemove", mynction);
function mynction() {
document.getElementById("afric").innerHTML = Math.random();
}
function removeHandler() {
document.getElementById("myDIV").removeEventListener("mousemove", mynction);
}
</script>
</html>