-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtmlDom.js
More file actions
330 lines (311 loc) · 9.93 KB
/
htmlDom.js
File metadata and controls
330 lines (311 loc) · 9.93 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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
//Validating the form
{
function formValidationText() {
let x = document.forms["form1"]["yourName"].value;
if (x == "") {
alert("Input not a valid text!");
return false;
} else if (!isNaN(x)) {
alert("You cannot enter number!");
return false;
}
}
//Input password validation
function formValidationPassword() {
const y = document.forms["form2"]["yourPassword"].value;
if (y == "") {
alert(`Input can not be blank!`);
return false;
} else if (isNaN(y)) {
alert(`Input must be a legal number.`);
return false;
}
}
{
//title checking of the html page
let x = document.getElementById("title_Checking");
x.innerHTML = document.title;
setTimeout(() => {
//Changing css style using DOM
x.style.color = "gold";
x.style.fontSize = "50px";
}, 5000);
}
{
//Changing HTML attribute
function lighOn() {
const x = document.querySelector("#imageOfLight");
x.src = "img/light_on.png";
}
function lightOff() {
const y = document.getElementById("imageOfLight");
y.src = "img/light-off.png";
}
{
let buttonStyle1 = document.querySelector(".button");
buttonStyle1.style.width = "100px";
buttonStyle1.style.backgroundColor = "gold";
buttonStyle1.style.outline = "none";
buttonStyle1.style.border = "none";
buttonStyle1.style.borderRadius = "50px";
buttonStyle1.style.height = "30px";
buttonStyle1.style.fontFamily = "Pacifico";
buttonStyle1.style.cursor = "pointer";
}
{
let buttonStyle2 = document.querySelector("#button");
buttonStyle2.style.width = "100px";
buttonStyle2.style.backgroundColor = "gold";
buttonStyle2.style.outline = "none";
buttonStyle2.style.border = "none";
buttonStyle2.style.borderRadius = "50px";
buttonStyle2.style.height = "30px";
buttonStyle2.style.fontFamily = "Pacifico";
buttonStyle2.style.cursor = "pointer";
}
}
//JS animation part
{
function animation() {
const ani = document.getElementById("animationBox");
let pos = 0;
let id = null;
clearInterval(id);
id = setInterval(mainAnimationFun, 1);
function mainAnimationFun() {
if (pos === 400) {
clearInterval(id);
} else {
pos++;
ani.style.top = pos + "px";
ani.style.left = pos + "px";
ani.innerHTML = 4;
ani.style.zIndex = 1;
}
}
}
}
{
//3rd animation
function animation2() {
const docId = document.getElementById("animationBox2");
let pos = 0;
const clearInt = setInterval(myAnima, 1);
function myAnima() {
if (pos < 400) {
pos++;
docId.style.right = pos + "px";
docId.style.top = pos + "px";
docId.innerHTML = 3;
docId.style.zIndex = 1;
} else {
clearInterval(clearInt);
// docId.style.zIndex = -1;
}
}
}
}
{
//3rd animation
function animation3() {
const myMove = document.getElementById("myMoveAnimation");
let pos = 0;
const clear = setInterval(myAni, 1);
function myAni() {
if (pos < 400) {
pos++;
myMove.style.bottom = pos + "px";
myMove.style.left = pos + "px";
myMove.innerHTML = 2;
} else {
clearInterval(clear);
}
}
}
}
{
//4th animation
function animation4() {
const myMove1 = document.getElementById("myMoveAnimation2");
let position = 0;
const cleInt = setInterval(myMov, 1);
function myMov() {
if (position < 400) {
position++;
myMove1.style.bottom = position + "px";
myMove1.style.right = position + "px";
function changin() {
myMove1.innerHTML = 1;
}
setTimeout(changin, 1500);
} else {
clearInterval(cleInt);
}
}
}
}
//5th animation
{
function myWidthAnimaTion() {
const doc = document.getElementById("myMovAnimation5");
let wid = 50;
const cle = setInterval(myWid, 50);
function myWid() {
if (wid > 20) {
wid--;
doc.style.width = wid + "px";
doc.style.height = wid + "px";
doc.style.left = 215 + "px";
doc.style.top = 215 + "px";
doc.innerHTML = 6;
doc.style.zIndex = 1;
} else {
clearInterval(cle);
}
}
}
}
//6th animation
function mySizeIncreseAni() {
const docOfEle = document.getElementById("myMovAnimation6");
let size = 20;
const clearingInt = setInterval(reSize, 50);
function reSize() {
if (size < 50) {
size++;
docOfEle.style.width = size + "px";
docOfEle.style.height = size + "px";
docOfEle.innerHTML = 5;
} else {
clearInterval(clearingInt);
}
}
}
{
//button 6
//Using "addEventListener()"
const button6 = document.getElementById("button6");
button6.addEventListener("click", mySizeIncreseAni);
button6.addEventListener("click", myWidthAnimaTion);
button6.addEventListener("click", animation4);
button6.addEventListener("click", animation3);
button6.addEventListener("click", animation2);
button6.addEventListener("click", animation);
const removeAddEvent = document.getElementById('button7');
}
{
//Button for DOM Event
const textOfButton = document.querySelector('.buttonForEvent');
function txt1() {
textOfButton.innerHTML = 'What\'s your name?';
}
function txt2() {
textOfButton.innerHTML = `Nice to meet you :)`;
}
function txt3() {
textOfButton.innerHTML = `Hope, see you again.`
}
}
const txtButtonChange = document.getElementById('buttonForEvent');
txtButtonChange.addEventListener('mouseover', txt1);
txtButtonChange.addEventListener('click', txt2);
txtButtonChange.addEventListener('mouseout', txt3);
{
//Input "onchange" event
function onChange() {
const inputValue = document.forms['form4']['upperCase'];
inputValue.value = inputValue.value.toUpperCase();
}
const buttonOnChange = document.getElementById('upperCase');
buttonOnChange.addEventListener('change', onChange)
{
const makeLowerCase = () => {
const lowerCaseText = document.forms['form5']['inputLowerCase'];
lowerCaseText.value = lowerCaseText.value.toLowerCase();
}
const lowerCaseB = document.querySelector('#inputLowerCase');
lowerCaseB.addEventListener('change', makeLowerCase);
}
{
//Removing blank space from input
let removingBlankSpace = () => {
const valueOfInput = document.forms["form6"]["trim"];
valueOfInput.value = valueOfInput.value.trim();
}
const inputStri = document.getElementById('trim');
inputStri.addEventListener('change', removingBlankSpace);
}
{
//Multiple alert in the same button
let firstAlert = () => {
alert(`Read our privacy statement before start!`);
}
let secondAlert = () => {
alert(`Don't break any rules otherwise your account will be restricted!`);
}
const alertButton = document.querySelector('#multipleAlert');
alertButton.addEventListener('click',firstAlert);
alertButton.addEventListener('click', secondAlert);
}
}
{
//Input validation
let funInput = () => {
const inputValues = document.forms['form7']['formVal'];
inputValues.placeholder = "Enter at least 8 digit";
}
let inputValues = document.forms['form7']['formVal'];
inputValues.addEventListener('mouseover', funInput);
inputValues.addEventListener('click', () => {
const inputValues = document.forms['form7']['formVal'];
inputValues.placeholder = "Don't do any mistake!";
})
//Validation code here
const isValidInput = () => {
const isValid = document.forms['form7']['formVal'].value;
const printRes = document.getElementById('resTex');
if(isValid === '') {
alert(`Input can not be submitted blank :(`);
return false;
} else if(isNaN(isValid)) {
alert(`Input must be legal number.`)
} else {
printRes.innerHTML = `Input is ok, and the value of input is: ${isValid}`;
}
}
const form7 = document.getElementById('form7');
form7.addEventListener('submit', isValidInput);
}
{
//Node relationship
document.getElementById('printNodeText').innerHTML = document.getElementById('accessNodeText').childNodes[0].nodeValue;
}
//Dynamically appending node element to HTML
{
const para1 = document.createElement("p");
const textNode = document.createTextNode("Fuck you boy");
para1.appendChild(textNode);
const div1Place = document.getElementById("divOfAppend");
div1Place.appendChild(para1);
//Creating another node
const para2 = document.createElement('p');
const para2Text = document.createTextNode('He is not a good boy.');
para2.appendChild(para2Text);
//insert 'para2' after 1st child and before 2nd child of div
const p2 = document.getElementById("p2");
div1Place.insertBefore(para2, p2);
//Remove the element that contain 'p3' id in the following div
const p3Id = document.querySelector('#p3');
p3Id.remove(); //But this method not compitible with all browser.
//So try to do it another way that is more smarter than this one
//Remove the element that contain 'p5' id in the following div using "removeChild()"
const p5 = document.getElementById('p5');
div1Place.removeChild(p5);
//Replace a child (remove the element that contain 'p6' id) with another element of the current div element
let p6 = document.querySelector('#p6');
const newPara = document.createElement('p');
const newParaText = document.createTextNode('He always flirt different girls.');
newPara.appendChild(newParaText);
div1Place.replaceChild(newPara, p6);
}
}