-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-11.html
257 lines (228 loc) · 7.32 KB
/
index-11.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="keywords" content="Assignment" />
<title>Coding Assisement</title>
<link rel="stylesheet" href="./style.css" />
<style>
img{
width: 100%;
}
</style>
</head>
<body>
<h2>11. DOM</h2>
<!-- ====== write code -->
<div class="Que">
<p>Que.1 Write the code to access element which is having id as "text"
<br>Project: <a href="./projects/dom-2/index-1.html">click Here</a>
</p>
<pre>
<!DOCTYPE html>
<html>
<head>
<title>access element</title>
</head>
<body>
<h1 id="text">This is text id</h1>
<script>
const element = document.getElementById("text");
console.log(element); // <h1 id="text">This is text id</h1>
</script>
</body>
</html>
</pre
>
<p>Que.2 Write the code to access element which is having tag as "h1"
<br> Project: <a href="./projects/dom-2/index-2.html">click Here</a>
</p>
<pre>
<!DOCTYPE html>
<html>
<head>
<title>access element</title>
</head>
<body>
<h1>This is text in h1 tag</h1>
<script>
const element = document.getElementsByTagName("h1");
console.log(element); // HTMLCollection [h1]
let content = element[0].innerText;
console.log(content); // This is text in h1 tag
</script>
</body>
</html>
</pre
>
<p>
Que.3 Write the code to access element which is having class as "box"
<br> Project: <a href="./projects/dom-2/index-3.html">click Here</a>
</p>
<pre>
<!DOCTYPE html>
<html>
<head>
<title>access element</title>
</head>
<body>
<div class="box">box-1</div>
<script>
const element = document.getElementsByClassName("box");
console.log(element); // HTMLCollection(1)
let content = element[0].innerText;
console.log(content); // box-1
</script>
</body>
</html>
</pre
>
<p>
Que.4 <h1>Hello </h1> <br />
Change the heading from "Hello" to "Hello World" using DOM functions
<br> Project: <a href="./projects/dom-2/index-4.html">click Here</a>
</p>
<pre>
<!DOCTYPE html>
<html>
<head>
<title>Change heading text using DOM functions</title>
</head>
<body>
<h1 id="myHeading">Hello</h1>
<script>
const heading = document.getElementById("myHeading");
heading.textContent = "Hello World";
</script>
</body>
</html>
</pre
>
<p>
Que.5 Create three cards on HTML page and arrange them using flex
property in row or horizontal direction and also create button at the
bottom named "Change Flex direction". When user clicks on this button,
the cards arrangement should be changed to vertical direction.
<br> Project: <a href="./projects/dom-2/index-5.html">click Here</a>
</p>
<pre>
<!DOCTYPE html>
<html>
<head>
<title>Flexbox cards</title>
<style>
.container {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.card {
background-color: #ff0808;
padding: 10px;
margin: 10px;
width: 200px;
height: 200px;
}
</style>
</head>
<body>
<div class="container">
<div class="card">Card 1</div>
<div class="card">Card 2</div>
<div class="card">Card 3</div>
</div>
<button id="changeFlexDirection">Change Flex Direction</button>
<script>
const button = document.getElementById("changeFlexDirection");
const container = document.querySelector(".container");
button.addEventListener("click", function() {
container.style.flexDirection = "column";
});
</script>
</body>
</html>
</pre
>
<p>Que.6 What’s the difference between window vs document?</p>
<img src="./images/table.jpg" alt="window vs document">
<p>
Que.7 <h1>Hello </h1> <br />
Add one style attribute and give text color as red and id attribute and
give the id value as "heading" in the above given h1 tag using DOM
functions
<br> Project: <a href="./projects/dom-2/index-7.html">click Here</a>
</p>
<pre>
<!DOCTYPE html>
<html>
<head>
<title>Change heading style using DOM functions</title>
</head>
<body>
<h1 id="heading">Hello</h1>
<script>
const heading = document.getElementById("heading");
heading.setAttribute("style", "color: red;");
</script>
</body>
</html>
</pre
>
<p>Que.8 Create an HTML page having content as Hello world and a button named Replace Text.
When user will click on this button page content should be changed to "Welcome to Elevation academy"
<br> Project: <a href="./projects/dom-2/index-8.html">click Here</a></p>
<pre>
<!DOCTYPE html>
<html>
<head>
<title>click on button</title>
</head>
<body>
<p id="text">Hello world</p>
<button onclick="replaceText()">Replace Text</button>
<script>
function replaceText() {
const text = document.getElementById("text");
text.innerText = "Welcome to Elevation academy";
}
</script>
</body>
</html>
</pre
>
<p>Que.9 Write code to implement timer clock using JS -- display HH:MM:SS -- the time should keep updating every second
<br> Project: <a href="./projects/dom-2/index-9.html">click Here</a>
</p>
<pre>
<!DOCTYPE html>
<html>
<head>
<title>timer clock using JS</title>
</head>
<body>
<h1 id="timer">00:00:00</h1>
<script>
setInterval(function () {
const timer = document.getElementById("timer");
const now = new Date();
const hours = now.getHours().toString().padStart(2, "0");
const minutes = now.getMinutes().toString().padStart(2, "0");
const seconds = now.getSeconds().toString().padStart(2, "0");
const currentTime = hours + ":" + minutes + ":" + seconds;
timer.innerText = currentTime;
}, 1000);
</script>
</body>
</html>
</pre
>
<p>Que.10 Project: <a href="./projects/dom-1/index.html">click Here</a></p>
</div>
<div class="container">
<div class="row"><a href="./index-10.html">Back</a></div>
<div class="row"><a href="./index-12.html">Next</a></div>
</div>
</body>
</html>