-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOM_2.html
More file actions
65 lines (54 loc) · 2.01 KB
/
DOM_2.html
File metadata and controls
65 lines (54 loc) · 2.01 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DOM</title>
</head>
<body style="background-color: #212121; color: #ffffff;">
<div class="parent">
<div class="day">Monday</div>
<!-- this is for comment -->
<div class="day">Tuesday</div>
<div class="day">Thruday</div>
<div class="day">Friday</div>
</div>
<script>
const parent = document.querySelector('.parent')
console.log(parent);
console.log(parent.children);
console.log(parent.children[1]);
// for (let i=0; i<parent.children.length; i++) {
// console.log(parent.children[i].innerHTML);
// }
// OR
for (const i in parent.children.length) {
console.log(parent.children[i].innerHTML);
}
parent.children[1].style.color ='orange'
console.log(parent.firstElementChild); //Access 1st child
console.log(parent.lastElementChild); //Access last child
const dayOne= document.querySelector('.day')
console.log(dayOne);
console.log(dayOne.parentElement); //Acees parent element Means all the element
console.log(dayOne.nextElementSibling); //Acees siblings
// console.log("Nodes" , parent.childNodes);
// child node is a complete tree struchure , count a line of code also count a next line and
// also count a comment
// ******************* how to creat a Node list Programetly***********
// *********** this is how wo generate a document,slect ,change
const h1=document.createElement('h1')
console.log(h1);
h1.className = 'main'
h1.id = Math.round(Math.random() * 10 + 1)
h1.setAttribute('title' , 'generated title')
h1.style.backgroundColor='purple'
h1.style.color='pink'
h1.style.padding='20px'
// h1.innerText="Shifa Rabbani" // or
const addText = document.createTextNode("Shifa Rabbani Gundapour")
h1.appendChild(addText)
document.body.appendChild(h1) //Now attach these all in to a documnet page
</script>
</body>
</html>