-
Notifications
You must be signed in to change notification settings - Fork 0
/
DOM.html
164 lines (108 loc) · 4.13 KB
/
DOM.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.heading{
text-align: center;
padding: 20px;
background-color: blanchedalmond;
border-bottom: 3px solid blue;
cursor: pointer;
}
.border{
border: 3px dotted red;
}
</style>
</head>
<body>
<h1 id="el1" onclick="alert('')">Hello Javascript</h1>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<div class="block1">
</div>
<h1>Form</h1>
<form action="">
<select name="" id=""></select>
</form>
<a href="https://ss.com" title="testing attributes">SS.COM</a>
<h1>Gallery</h1>
<div class="gallery"></div>
<script>
// DOM = Document Object Model
// console.log(document.body);
// console.log(document.title);
// document.title = "Hello JS";
// document.body.innerHTML = "<h1>Hello JS</h1>";
// document.body.innerHTML += "<h2>Hello JS2</h2>";
// document.body.innerText += "<h2>Hello JS2</h2>";
let h1 = document.getElementById("el1");
let p = document.getElementsByTagName("p");
let div1 = document.getElementsByClassName("block1");
let div2 = document.querySelector("div.block1");
let paragraphs = document.querySelectorAll("p");
let select = document.querySelector("form select");
let galleryDiv = document.querySelector(".gallery");
let hyperlink = document.querySelector("a");
let galleryData = [
"https://images.pexels.com/photos/417074/pexels-photo-417074.jpeg?cs=srgb&dl=pexels-james-wheeler-417074.jpg&fm=jpg",
"https://upload.wikimedia.org/wikipedia/commons/thumb/c/c8/Altja_j%C3%B5gi_Lahemaal.jpg/1200px-Altja_j%C3%B5gi_Lahemaal.jpg",
"https://images.squarespace-cdn.com/content/v1/61c4da8eb1b30a201b9669f2/1696691175374-MJY4VWB1KS8NU3DE3JK1/Sounds-of-Nature.jpg",
"https://img.freepik.com/free-photo/painting-mountain-lake-with-mountain-background_188544-9126.jpg",
"https://www.bsr.org/images/heroes/bsr-focus-nature-hero.jpg",
"https://d19h8kn98xvxar.cloudfront.net/images/_hero/connectwithnature.jpg"
];
h1.innerText = "Hello World!";
p[0].innerText = h1.innerText;
div1[0].innerText = h1.innerText;
for(let i=0;i<paragraphs.length;i++){
paragraphs[i].innerText = `Paragraph ${i+1}!`;
}
// console.log(div2,paragraphs);
for(let year = 1980;year <= 2024;year++){
select.innerHTML += `
<option value="${year}">${year}</option>
`;
}
for(let image of galleryData){
galleryDiv.innerHTML += `
<img src="${image}" alt="image" width="100%">
`;
}
galleryDiv.style.display = "grid";
galleryDiv.style.gridTemplateColumns = "auto auto auto";
galleryDiv.style.gap = "10px";
// div2.innerText = hyperlink.getAttribute("href");
div2.innerText = hyperlink.href;
let url = "https://google.com";
hyperlink.href = url;
let headings = document.querySelectorAll("h1");
for(h1 of headings){
h1.title = h1.innerText;
h1.classList.add("heading");
h1.classList.add("border");
// h1.classList.toggle("heading");
// h1.classList.toggle("heading");
h1.onclick = function(){
this.classList.toggle("heading");
}
}
let img2 = document.createElement("img");
img2.src = galleryData[0];
img2.alt = "New Image";
img2.width = 300;
document.body.appendChild(img2);
document.body.appendChild(img2);
document.body.insertBefore(img2,document.querySelector("#el1"));
galleryDiv.onclick = function(){
this.remove();
}
select.removeChild(select.querySelector("option"));
</script>
</body>
</html>