-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpractice.js
288 lines (201 loc) · 7.52 KB
/
practice.js
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
console.log('...Started...\n\n');
// var imgTags = document.getElementsByTagName('img')
// var imgArray = Array.from(imgTags);
// imgArray.forEach((cur) => {
// console.log(cur);
// })
// let clientsC = document.getElementsByClassName('client1');
//
// Array.from(clientsC).forEach((cur) => {
// console.log(cur);
// })
// console.log(clientsC);
// let mediaImgs = document.querySelector('.foot div:nth-child(2) .mediaLogos img')
// console.log(mediaImgs);
// let mediaImgs = document.querySelectorAll('.foot > div:nth-child(2) > .mediaLogos > img')
// // console.log(mediaImgs);
//
// Array.from(mediaImgs).forEach((cur, index, all) => {
// console.log(cur);
// })
// var partners = document.querySelectorAll('.foot > div:nth-child(3) > ul > li')
// Array.from(partners).forEach((cur) => {
// console.log(cur);
// })
//WORKS THE SAME WAY AS::::::::
// partners.forEach((cur) => {
// cur.textContent += ' Test';
// console.log(cur.textContent);
// })
// document.querySelector('#sendBtn').addEventListener('click', () => {
// var inputs = document.querySelectorAll('input').value;
// console.log(inputs);
// // Array.from(inputs).forEach((cur) => {
// // console.log(cur);
// // })
//
// inputs = '';
//
// })
// let clientName = document.querySelectorAll('.client1 > h2');
// clientName.forEach((cur) => {
// console.log(cur.innerHTML);
// cur.innerHTML = '<h4>Steve Harvey</h4>'
// cur.innerHTML += '<h5>TV Presenter</h5>';
// })
// let clientMsg = document.querySelectorAll('.client1 > i');
// clientMsg.forEach((cur) => {
// console.log(cur.innerHTML);
// cur.innerHTML = '"' + cur.innerHTML + '"';
// })
// const init = () => {
// document.querySelector('.success').style.display = 'none';
// document.querySelector('.failed').style.display = 'none';
// inputsFun();
// }
// let inputsFun = () => {
// document.querySelector('#sendBtn').addEventListener('click', () => {
//
// var pasteMsg = document.querySelectorAll('textarea');
// var selectInput = document.querySelectorAll('.messagebox > div:nth-child(2) > input');
//
// pasteMsg.forEach((msg) => {
// selectInput.forEach((name) => {
// if(name.value != "" && msg.value != ""){
// document.querySelector('.bottom > h2').textContent = '~' + name.value;
// document.querySelector('.client1 > i').textContent = msg.value;
// document.querySelector('.success').style.display = 'block';
// msg.value = "";
// name.value = "";
// }else {
// document.querySelector('.failed').style.display = 'block';
// }
// });
// });
// var pasteMsg = document.querySelectorAll('input');
// pasteMsg.forEach((cur) => {
// cur.value = "";
// });
// // var client1 = document.querySelector('.com1 > i');
// // // console.log(client1.innerHTML);
// // client1.parentElement.nextElementSibling.querySelector('.com2 > i').innerHTML = '<div><i>This is the newly added content ::: <br></i></div>';
//
// });
// }
//
// var msgBoxPressed = document.querySelectorAll('.messagebox');
// msgBoxPressed.forEach((pasteInfo) => {
// pasteInfo.addEventListener('keypress', (e) => {
// if(e.keyCode === 13) {
// console.log(e.keyCode);
// inputsFun();
// }
// // if(e.keyCode === 13) {
// // inputsFun();
// // }
// })
// })
//
// init();
// document.addEventListener('keypress', function(event){
// if(event.keyCode === 13 || event.while === 13) {
// inputsFun();
// console.log('Entered');
// }
// });
// var one = document.querySelector('.responses div:nth-child(4) h2');
// console.log(one.nodeType);
// console.log(one.hasChildNodes());
//
// var foot = document.querySelector('.foot');
// var clonedFoot = foot.cloneNode(false); //the whole bunch; Including Nestings
// var clonedFoot = foot.cloneNode(false);
// console.log(clonedFoot);
//DOM TRAVERSAL
//Up ::: Parent to Child
//var footImgs = document.querySelector('.foot');
// console.log(footImgs.parentNode);
// console.log(footImgs.parentElement.parentElement.parentElement);
////Down :: Child to parent
// console.log(footImgs.childNodes); //Returns NODELIST
// console.log(footImgs.children); //Returns HTML Collection
// footImgs.childNodes.forEach((cur) => {
// console.log(cur);
// })
// Array.from(footImgs.children).forEach((cur) => {
// console.log(cur);
// })
//Child to child:: Same level Siblings
//var client1 = document.querySelector('.client1');
// console.log(client1.nextSibling);
// console.log(client1.nextElementSibling);
// console.log(client1.previousSibling);
// console.log(client1.previousElementSibling);
// var mediaFoot = document.querySelector('.media');
// var sth = mediaFoot.nextElementSibling.querySelector('ul').innerHTML += ' <li>Client Posted</li>';
// console.log(sth);
// var client1 = document.querySelector('.com1 > i');
// // console.log(client1.innerHTML);
// client1.parentElement.nextElementSibling.querySelector('.com2 > i').innerHTML = '<div><i>This is the newly added content ::: <br> "client1.parentElement.nextElementSibling.querySelector(\'.com2 > i\').innerHTML = \'<div><i>--This is the newly added content--</i></div>"</i></div>'
////::::::EVENTS:::::::::::::::
// var nav = document.querySelector('.navigation').addEventListener('click', (e) => {
// console.log(e.target);
// console.log(e);
// })
//
const deleteBtn = document.querySelectorAll('.deleteBtn');
deleteBtn.forEach(btn => {
btn.addEventListener('click', e => {
const deleteItem = e.target.parentElement.parentElement;
deleteItem.parentNode.removeChild(deleteItem);
})
})
/////////////////////////////////////////////////
//>>>>>>>FORMS AND INPUTS.
// var form = document.forms['inputForm'];
// form.addEventListener('submit', (e) => { //When Add button is clicked, the Form emits a Submit Event.
// e.preventDefault();
// var value = form.querySelector('input[type="text"]').value;
// console.log(value);
//
// //Create Elements::
// const responses = document.querySelector('.responses');
// const keepReading = document.querySelector('.keepReading');
// const client1 = document.querySelector('.client1');
// const i = document.createElement('i');
// const btn = document.createElement('button');
// const h2 = document.createElement('h2');
// const div1 = document.createElement('div');
// const div2 = document.createElement('div');
// const div3 = document.createElement('div');
// const bottom = document.querySelector('.bottom');
// //const newClient = document.createElement('.client1');
//
// //console.log(responses);
//
// //Add content to the Tags
// i.textContent = value;
// btn.textContent = 'DELEETE';
// h2.textContent = '~Anonymous';
//
// //Add Classes::
// btn.classList.add('deleteBtn');
// div1.classList.add('bottom');
// div2.classList.add('client1');
// div3.classList.add('responses');
//
// //Append to DOM
// div1.appendChild(h2);
// div1.appendChild(btn);
// div2.appendChild(i);
// div2.appendChild(div1);
// div3.appendChild(div2);
// //responses.appendChild(client1);
// //keepReading.appendChild(client1);
//
// //var responsesLast = document.querySelector('.client1:last-child');
// //console.log(responsesLast);
//
//
// })
console.log('\n\n\...End...');