-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicJavaScript_5.js
More file actions
340 lines (269 loc) · 10.8 KB
/
Copy pathBasicJavaScript_5.js
File metadata and controls
340 lines (269 loc) · 10.8 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
331
332
333
334
335
336
337
338
339
340
/*
DOM And Manupalation:
Document Object Model ==> DOM
// Go to --> "Browser" --> Click " Inspect" --> Go Inside Of "Console" --> Then Search then In Below :
console.log(window);
console.log(window.document);
console.log(document);
console.log(document.); // "document." document এ {.}ডট দেওয়ার পর Suggestion-List এ যেইগুলা আসবে,যেটা ইচ্ছা ঐটা দেখা যাবে । যেমন ঃ console.log(document.linkColor);
console.dir(document);
*/
/*
Actually, How To Work " DOM " in "Browser" :
Diagram:-
"Element" inside ==> Window=>Document=>Html=>1.Head{1.Title[Text Node],2.Meta[Attribute]},2.Body{1.div{1.h1[Attribute,Text Node],2.paragrap[Text Node]},2.Attribute}
*/
// NodeList: {All DOM Selectors Nodelist and HTMLAllCollection}:-
document.getElementById();
// document.getElementById("firstHeading").innerHTML = "<h1>Al-Arafat</h1>"
// console.log(window);
// VM224:1 Window {window: Window, self: Window, document: document, name: '', location: Location, …}
// undefined
// window
// Window {window: Window, self: Window, document: document, name: '', location: Location, …}$: ƒ (selector,context)Geo: {country: 'BD', region: 'C', city: 'Dhaka', lat: 23.84, lon: 90.32, …}
// [[Prototype]]: HTMLDocument
// undefined
// Dom:
// document.getElementById("title")
// <h1 id="title" class="heading">DOM Learning</h1>
// document.getElementById("title").id
// 'title'
// document.getElementById("title").class
// undefined
// document.getElementById("title").className
// 'heading'
// document.getElementById("title").getAttribute()
// document.getElementById("title").getAttribute("id")
// 'title'
// document.getElementById("title").getAttribute("class")
// 'heading'
// document.getElementById("title").setAttribute("class",'test')
// document.getElementById("title").setAttribute("class",'test heading')
// const Title = document.getElementById("title")
// Title.style.backgroundColor = "blue"
// const Title = document.getElementById("title")
// undefined
// Title.style.backgroundColor = "blue"
// 'blue'
// Title.style.padding ='15px"
// VM2395:1 Uncaught SyntaxError: Invalid or unexpected tokenUnderstand this error
// Title.style.padding ='15px'
// '15px'
// Title.style.borderRadius ='20px'
// '20px'
// Title.textContent
// 'DOM Learning'
// Title.innerHTML
// 'DOM Learning'
// Title.innerHTML
// 'DOM Learning'
//Title.innerText
// document.getElementsByClassName("heading")
// document.getElementsByClassName("heading")
// document.getElementsByClassName("heading")
// HTMLCollection [h1#title.heading, title: h1#title.heading]
// document.querySelector("h2")
// <h2>sldfjkghkjsd</h2>
// document.querySelector(".title")
// null
// document.querySelector(".heading")
// <h1 id="title" class="heading">DOM Learning</h1>
// document.querySelector(" #title")
// <h1 id="title" class="heading">DOM Learning</h1>
// document.querySelector("input type[password]")
// document.querySelector("input type['password']")//Error/incoorect
// document.querySelector("input [type = 'password']")
// document.querySelector("input type[password]")
// document.querySelector("ul")
// const myUl=document.querySelector("ul")
// myUl.querySelector("ul")
// const myLi=myUl.querySelector("ul")
// myLi.querySelector("li")
// myLi.style.backgroundColor='blue'
// myLi.style.paddingr='15px'
// myLi.innerText
// myLi.innerText="five"
// document.querySelectorAll(" p:first-child")
// document.querySelectorAll(" h2")
// document.querySelectorAll(" li")
// const Li_list= document.querySelectorAll(" li")
// Li_list.style.color = 'green'//Error/incorrect
// Li_list[0].style.color = 'green'//now correct
// Li_list.forEach(function( li) {
// li.style.backgroungColor ='blue'
// })
// const myH1= document.querySelectorAll("h1")
// myH1.style.color = 'blue'//Error/incorrect
// myH1[0].style.color = 'blue'//now correct
// document.getElementsByClassName("list-item")
// const myClassList =document.getElementsByClassName("list-item")
// myClassList.forEach(function(li) {
// console.log(li);
// })//Error/incorrect
// Array.from(myClassList)
// const myConvertedArray = Array.from(myClassList)
// myConvertedArray.forEach(function(li) {
// li.style.color ='sky-blue'
// })//correct
// NodeList(3) [h2, h2, h2]0: "NodeList"get length: ƒ length()[[Prototype]]: Object
// Create , Edit And Remove :
// This is traversing code : parents => to => child ; child => to => parents
const myparent = document.querySelector(".parent")
// console.log(myparent);
// console.log(myparent.children);
// console.log(myparent.children[0]);
// console.log(myparent.children[1]);
// console.log(myparent.children[2]);
// console.log(myparent.children[3]);
// console.log(myparent.children[3].innerHTML);
for (let i = 0; i < myparent.children.length; i++) {
// const element = myparent.children[i];
// console.log(element);
// console.log(myparent.children[i].innerHTML);
}
// myparent.children[2].style.color = "blue"
// console.log(myparent.firstElementChild);
// console.log(myparent.lastElementChild);
// console.log(myparent.secondElementChild);
const dayOne = document.querySelector(".day")
// console.log(dayOne);
// console.log(dayOne.parentElement);
// console.log(dayOne.nextElementSibling);
// console.log(dayOne.nextSibling);
// console.log("NODES: ",myparent.childNodes);
// Second Script for another xmple:
// create node list :
const div = document.createElement('div')
console.log(div);
div.className = "main"
// div.id = "myId"
div.id = Math.round(Math.random()*10 + 1)
div.setAttribute("title","generated title")
div.style.backgroundColor = "green"
div.style.color = "red"
div.style.padding = "12px"
// div.innerText = "Create A New Element In DOM"
const addText = document.createTextNode("Create A New Element In DOM")
div.appendChild(addText)
document.body.appendChild(div)
// Edit and Remove Elements
function addLanguage(langName) {
const li = document.createElement('li');
li.innerHTML ='${langName}'
document.querySelector('.language').
appendChild(li)
}
addLanguage("Python")//Occurs "Error"
addLanguage("Typescript")//Occurs "Error"
// Or,
function addOptiLanguage(langName) {
const li = document.createElement('li');
/*
const addText = document.createTextNode(langName)
li.appendChild(addText)
*/
li.appendChild(document.createTextNode(langName))
document.querySelector('.language').appendChild(li)
}
addOptiLanguage("Golang")
// Edit:
const secondLang = document.querySelector('li:nth-child(2)')
console.log(secondLang);
// secondLang.innerHTML = 'Mojo'
const newli = document.createElement("li")
newli.textContent = "Mojo"
secondLang.replaceWith(newli)
const firstLang = document.querySelector("li:first-child")
firstLang.outerHTML = '<li>TypeScript</li>'
// Remove:
const thirdLang = document.querySelector("li:third-child");
thirdLang.remove()//Error Occurs
// document.getElementById("div-02");
const lastLang = document.querySelector('li:last-child');
lastLang.remove()//Error Occurs
// Events:
// HTML code copy করতে হবে হিতেশ ভাই এর github hitesh থেকেঃ
// Older version,Don't use in this ,because company don't like it:
// 1. alt = "" onclick="alert('owl')" //inside in HTML
//2. document.getElementById("owl").onclick = function () {
// alert("owl clicked")
// }
// 3.attachEvent()
//4.jQuery- jQuery.on()
// Use it:
//5.
// document.getElementById("owl").addEventListener('click',function () {
// alert("owl clicked again")
// })
document.getElementById("owl").addEventListener('click',function (events) {
// alert("owl clicked again")
console.log(events);
},false) //false =>default
// type,timestamp,defaultPrevented,target,toElement,srcElement,currentTarget,clientX,clientY,screenX,screenY,altkey,ctrlkey,shiftkey,keycode ==> Study on this topics
// What is Event Propogation?
//For False{Bubbling Mood}:Bottom to Top
document.getElementById("images").addEventListener('click',function (events) {
// alert("owl clicked again")
console.log('clicked inside the ul');
},false)
document.getElementById("owl").addEventListener('click',function (events) {
// alert("owl clicked again")
console.log("owl clicked");
},false)
// অথবা,
document.getElementById("images").addEventListener('click',function (events) {
// alert("owl clicked again")
console.log('clicked inside the ul');
})
document.getElementById("owl").addEventListener('click',function (events) {
// alert("owl clicked again")
console.log("owl clicked");
})
//For True{Capturing Mood}: Top to Bottom
document.getElementById("images").addEventListener('click',function (events) {
// alert("owl clicked again")
console.log('clicked inside the ul');
},true)
document.getElementById("owl").addEventListener('click',function (events) {
// alert("owl clicked again")
console.log("owl clicked");
},true)
document.getElementById("images").addEventListener('click',function (events) {
// alert("owl clicked again")
console.log('clicked inside the ul');
},false)
document.getElementById("owl").addEventListener('click',function (events) {
// alert("owl clicked again")
console.log("owl clicked");
events.stopPropagation()
},false)
document.getElementById("google").addEventListener('click',function (events) {
// alert("owl clicked again")
// events.defaultPrevented() //This is bugs...
events.preventDefault()
events.stopPropagation()
console.log("google clicked");
},false)
// Project:যেই ছবির উপর click করবো,সেই ছবি যেন vanish হয়ে যায়।
document.querySelector('#images').addEventListener('click',function (event)
{
// console.log(event.target);
// console.log(event.target.parentNode);
console.log(event.target.targetName);
removeIt.remove()
// or,
// removeIt.parentNode.removeChild(removeIt)
})
document.querySelector('#images').addEventListener('click',function (event) {
// console.log(event.target);
// console.log(event.target.parentNode);
console.log(event.target.targetName);
if (event.target.targetName === 'IMG') {
console.log(event.target.id);
let removeIt = event.target.parentNode
removeIt.remove()
// or,
// removeIt.parentNode.removeChild(removeIt)
}
})
// ``````````````````````````` X ```````````````````````````