-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflatiron.html
326 lines (288 loc) · 10.4 KB
/
flatiron.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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Class 2 ~ Intermediate JS ~ Girl Develop It</title>
<meta name="description"
content="This is a proposed Girl Develop It NYC Intermediate JavaScript curriculum. The course is meant to be taught in 4 two-hour sections.">
<meta name="author" content="Girl Develop It">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/custom.css">
<link rel="stylesheet" href="css/theme/gdidefault.css" id="theme">
<!-- For syntax highlighting -->
<!-- light editor<link rel="stylesheet" href="lib/css/light.css">-->
<!-- dark editor-->
<link rel="stylesheet" href="lib/css/dark.css">
<link rel="stylesheet" href="lib/css/zenburn.css">
<link rel="stylesheet" href="plugin/accessibility-helper/css/accessibility-helper.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if (window.location.search.match(/print-pdf/gi)) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName('head')[0].appendChild(link);
}
</script>
<!-- If use the PDF print sheet so students can print slides-->
<link rel="stylesheet" href="css/print/pdf.css" type="text/css" media="print">
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h2>JavaScript</h2>
<h3>DOM manipulation</h3>
<p> By Mahdi Shadkam-Farrokhi</p>
</section>
<section>
<h1>Agenda</h1>
<ul>
<li>What is the DOM?</li>
<li>Selecting elements</li>
<li>Modifying elements</li>
<li>Creating elements</li>
<li>Appending elements</li>
<li>Deleting elements</li>
</ul>
</section>
<section>
<h2>How the browser works</h2>
<div class="halfblock fragment">
<p style="text-align: center;">How do we get this...</p>
<img src="img/site.png" alt="" width="450px" style="max-width: none;">
</div>
<div class="halfblock fragment">
<p style="text-align: center;">From this?</p>
<img src="img/html.jpg" alt="" width="450px" style="max-width: none;">
</div>
</section>
<section>
<h2>What is the DOM?</h2>
<p class="fragment">The browser translates HTML into JavaScript objects known as <strong>the Document Object
Model</strong></p>
<ul>
<li class="fragment">An HTML file is just text, but JS objects are "alive"</li>
<li class="fragment">The browser uses the DOM along with CSS and JavaScript files to render the website
properly</li>
<li class="fragment">The nested syntax from HTML carries over into the DOM in the form of nodes</li>
</ul>
</section>
<section>
<h2>From HTML to the DOM</h2>
<div class="halfblock fragment">
<p style="text-align: center;">HTML</p>
<pre><code class="xml" data-trim contenteditable>
<html>
<head>
<title>My Site</title>
</head>
<body>
<h2>Some Title</h2>
<p>First paragraph</p>
<p>Second paragraph</p>
</body>
</html>
</code></pre>
</div>
<div class="halfblock fragment">
<p style="text-align: center;">DOM</p>
<img src="img/dom.PNG" alt="">
</div>
<ul>
<li class="fragment">Remember, the DOM is just JavaScript!</li>
<li class="fragment">We can access the DOM as well as add, modify, and delete elements as we
like</li>
<li class="fragment">NOTE: only elements that are part of the DOM will be rendered</li>
</ul>
</section>
<section>
<h2>Finding an element(s)</h2>
<div class="fragment">
<p style="text-align: center;">HTML</p>
<pre><code class="xml" data-trim contenteditable>
<html>
<head>
<title>My Site</title>
</head>
<body>
<h2 id="mainTitle">Some Title</h2>
<p>First paragraph</p>
<p>Second paragraph</p>
</body>
</html>
</code></pre>
</div>
<div class="fragment">
<p style="text-align: center;">JavaScript</p>
<pre><code class="javascript" data-trim contenteditable>
// document.querySelector returns first matching element found
const h2 = document.querySelector("#mainTitle");
// document.querySelectorAll returns an array of all matching elements found
const all_ps = document.querySelectorAll("p");
</code></pre>
</div>
</section>
<section>
<h2>Modifying elements</h2>
<p class="fragment">DOM nodes/elements are objects with their own properties that can be modified!</p>
<div class="fragment">
<p style="text-align: center;">JavaScript</p>
<pre><code class="javascript" data-trim contenteditable>
// document.querySelector returns first matching element found
const h2 = document.querySelector("#mainTitle");
h2.innerText = "Something else!";
h2.style.color = "red";
</code></pre>
</div>
<div style="text-align: center;" class="halfblock fragment">
<p>BEFORE</p>
<img src="img/html_1.PNG" alt="">
</div>
<div style="text-align: center;" class="halfblock fragment">
<p>AFTER</p>
<img src="img/html_2.PNG" alt="">
</div>
</section>
<section>
<h2>Creating elements</h2>
<div class="fragment">
<p style="text-align: center;">JavaScript</p>
<pre><code class="javascript" data-trim contenteditable>
// document.createElement() creates a new node of the given tag string
const newH3 = document.createElement("h3");
newH3.innerText = "Some text";
</code></pre>
</div>
<div style="text-align: center;" class="halfblock fragment">
<p>BEFORE</p>
<img src="img/html_2.PNG" alt="">
</div>
<div style="text-align: center;" class="halfblock fragment">
<p>AFTER</p>
<img src="img/html_2.PNG" alt="">
</div>
<h4 class="fragment">Where is the h3?</h4>
</section>
<section>
<h2>Creating elements</h2>
<img class="fragment" src="img/dom_1.PNG" alt="" width="400px">
<p class="fragment">The node is not attached to the DOM, therefore it won't be rendered!</p>
</section>
<section>
<h2>Appending elements</h2>
<p class="fragment">Elements must be attached, or appended, to another element in the DOM to be rendered in the
browser</p>
<pre class="fragment"><code class="javascript" data-trim contenteditable>
// document.createElement() creates a new node of the given tag string
const newH3 = document.createElement("h3");
newH3.innerText = "Some text";
const body = document.querySelector("body"); // document.body
body.append(newH3);
</code></pre>
<div class="halfblock fragment">
<img src="img/dom_2.PNG" alt="" width="400px">
</div>
<div class="halfblock fragment">
<img src="img/html_3.PNG" alt="" width="400px">
</div>
</section>
<section>
<h2>Removing elements</h2>
<p class="fragment">Removing elements from the DOM is as easy as .remove()</p>
<pre class="fragment"><code class="javascript" data-trim contenteditable>
newH3.remove();
</code></pre>
<div class="halfblock fragment">
<img src="img/dom_1.PNG" alt="" width="300px" style="max-height: none;">
</div>
<div class="halfblock fragment">
<img src="img/html_2.PNG" alt="" width="400px">
</div>
<ul>
<li class="fragment">.remove() removes the element and all of it's attached children from the DOM</li>
<li class="fragment">If you keep a reference to the object (like in a variable), it still exists, just not as
part of the DOM!</li>
</ul>
</section>
<section>
<h3>FIN!</h3>
</section>
</div>
</div>
<footer>
<div class="copyright">
Intermediate JS - GDINYC
<a rel="license" href="http://creativecommons.org/licenses/by-nc/3.0/deed.en_US"><img
alt="Creative Commons License" style="border-width:0"
src="http://i.creativecommons.org/l/by-nc/3.0/80x15.png" /></a>
</div>
</footer>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [{
src: 'lib/js/classList.js',
condition: function () {
return !document.body.classList;
}
},
{
src: 'plugin/markdown/marked.js',
condition: function () {
return !!document.querySelector('[data-markdown]');
}
},
{
src: 'plugin/markdown/markdown.js',
condition: function () {
return !!document.querySelector('[data-markdown]');
}
},
{
src: 'plugin/highlight/highlight.js',
async: true,
condition: function () {
return !!document.querySelector('pre code');
},
callback: function () {
hljs.initHighlightingOnLoad();
}
},
{
src: 'plugin/zoom-js/zoom.js',
async: true
},
{
src: 'plugin/notes/notes.js',
async: true
},
{
src: 'plugin/accessibility-helper/js/accessibility-helper.js',
async: true,
condition: function () {
return !!document.body.classList;
}
}
]
});
</script>
</body>
</html>