-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment2.html
183 lines (168 loc) · 6.9 KB
/
assignment2.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.tailwindcss.com"></script>
<title>Assignment 2</title>
</head>
<body class="bg-stone-100 p-2">
<h1 class="text-4xl font-bold text-center">
Working with the DOM
</h1>
<div class="hover:bg-stone-200 p-2 border-b-2 border-black">
<h1 class="text-xl font-black">question 1</h1>
<ul class="text-sm">
<li> 1. Use JavaScript to select the img> element using getElementById( ).</li>
<li>2. Add a title attribute with the value "Bootcamp Image".</li>
<li>3. Print the img> element using console.log( ).</li>
</ul>
<h1 class="text-xl font-bold border-t-2 mt-3">
Solution
</h1>
<div>
<div class="w-32 h-32">
<img id="dynamic-box" src="/img/fitech-logo.png" alt="">
</div>
</div>
</div>
<div class="hover:bg-stone-200 p-2 border-b-2 border-black">
<h1 class="text-xl font-black">question 2</h1>
<ul class="text-sm">
<li> 1. Use querySelector() to select the input field with the class user-input.</li>
<li>2. Add a keydown event listener that prints "Key pressed" whenever a key is pressed.</li>
<li>3. Also print the current value of the input field using console.log() inside the event handler.</li>
</ul>
<h1 class="text-xl font-bold border-t-2 mt-3">
Solution
</h1>
<div>
<input type="text" class="user-input" placeholder="type something...">
</div>
</div>
<div class="hover:bg-stone-200 p-2 border-b-2 border-black">
<h1 class="text-xl font-black">question 3</h1>
<ul class="text-sm">
<li> 1. Use querySelectorAll() to select all elements with the class item. </li>
<li> 2. Change the second item’s text to "Updated Item 2".</li>
<li> 3. Print the NodeList of items using console.log( ).</li>
<li></li>
</ul>
<h1 class="text-xl font-bold border-t-2 mt-3">
Solution
</h1>
<div>
<ul>
<li class="item">item 1</li>
<li class="item">item 2</li>
</ul>
</div>
</div>
<div class="hover:bg-stone-200 p-2 border-b-2 border-black">
<h1 class="text-xl font-black">question 4</h1>
<ul class="text-sm">
<li> 1. Use JavaScript to select the button using getElementById( ).</li>
<li>2. Add a click event listener that changes the button text to "Button Clicked!" when clicked.</li>
<li> 3. Print "Button was clicked" inside the event handler using console.log( ).</li>
<li></li>
</ul>
<h1 class="text-xl font-bold border-t-2 mt-3">
Solution
</h1>
<div>
<a href="https://github.com" id="github-link"> Visit GitHub</a>
</div>
</div>
<div class="hover:bg-stone-200 p-2 border-b-2 border-black">
<h1 class="text-xl font-black">question 5</h1>
<ul class="text-sm">
<li>1. Use JavaScript to select all elements with the class box using getElementsByClassName().</li>
<li> 2. Change the background color of the second box to "yellow".</li>
<li> 3. Print the collection of elements using console.log( ).</li>
<li></li>
</ul>
<h1 class="text-xl font-bold border-t-2 mt-3">
Solution
</h1>
<div>
<div class="box"> Box 1</div>
<div class="box"> Box 2</div>
</div>
</div>
<div class="hover:bg-stone-200 p-2 border-b-2 border-black">
<h1 class="text-xl font-black">question 6</h1>
<ul class="text-sm">
<li>1. Use JavaScript to select the h2> element using querySelector() with the class .header.</li>
<li>2. Change its content to "Welcome to FiTech!".</li>
<li>3. Print the selected element using console.log( ).</li>
<li></li>
</ul>
<h1 class="text-xl font-bold border-t-2 mt-3">
Solution
</h1>
<h2 class="header text-2xl font-black text-green-500">Bootcamp Header</h2>
</div>
<div class="hover:bg-stone-200 p-2 border-b-2 border-black">
<h1 class="text-xl font-black">question 7</h1>
<ul class="text-sm">
<li> 1. Use JavaScript to select all p> elements using getElementsByTagName( ). </li>
<li>2.Change the content of the first paragraph to "This is the updated paragraph 1".</li>
<li>3. Print the p> elements collection using console.log( ).</li>
<li></li>
</ul>
<h1 class="text-xl font-bold border-t-2 mt-3">
Solution
</h1>
<div id="paragraph">
<p> This is paragraph 1</p>
<p> This is paragraph 2</p>
</div>
</div>
<div class="hover:bg-stone-200 p-2 border-b-2 border-black">
<h1 class="text-xl font-black">question 8</h1>
<ul class="text-sm">
<li>1. Use JavaScript to select the a> element using getElementById( ). </li>
<li> 2. Retrieve the value of the href attribute using getAttribute( ).</li>
<li>3. Print the value of the href attribute using console.log( ).</li>
<li></li>
</ul>
<h1 class="text-xl font-bold border-t-2 mt-3">
Solution
</h1>
<div>
<a href="https://github.com" id="gitHub-link"> Visit GitHub</a>
</div>
</div>
<div class="hover:bg-stone-200 p-2 border-b-2 border-black">
<h1 class="text-xl font-black">question 9</h1>
<ul class="text-sm">
<li>1. Use JavaScript to select the h1> element using getElementById( ) </li>
<li> 2. Change the content to "DOM Manipulation is Amazing!". </li>
<li> 3. Print the modified element using console.log( ).</li>
<li></li>
</ul>
<h1 class="text-xl font-bold border-t-2 mt-3">
Solution
</h1>
<div>
<h1 id="welcome-message">Welcome to The BootCamp</h1>
</div>
</div>
<div class="hover:bg-stone-200 p-2 border-b-2 border-black">
<h1 class="text-xl font-black">question 10</h1>
<ul class="text-sm">
<li>1. Select the div> element using getElementById().</li>
<li> 2. Change its width to 200px and background color to "green".</li>
<li> 3. Print the modified element using console.log( ).</li>
<li></li>
</ul>
<h1 class="text-xl font-bold border-t-2 mt-3">
Solution
</h1>
<div>
<div id="dynamic-Box" class="w-[100px] h-[100px] bg-red-500"></div>
</div>
</div>
<script src="assignment2.js"></script>
</body>
</html>