Add lesson 5: Selecting and changing elements

Daniel Tanaka 1 year ago
parent 77510e0a7b commit 5eb6df0cea64ef3933a6baa750687ef1bfeafec2
3 changed files with 41 additions and 0 deletions
+19-0lessons/05-selecting-and-changing-elements/README.md ADDED
@@ -0,0 +1,19 @@
1+# Lesson 5: Selecting and changing elements
2+
3+Selecting and changing elements comes up in almost every real JavaScript project. We start with the why, then write code together.
4+
5+Full lesson: [https://glibcode.net/courses/javascript-web/lessons/5](https://glibcode.net/courses/javascript-web/lessons/5)
6+
7+## Files
8+
9+- `dom.html`: selecting elements and changing their text and classes
10+
11+## Run it
12+
13+```sh
14+open dom.html # or double-click it
15+```
16+
17+## Exercises
18+
19+See [exercises.md](exercises.md). Ask in the forum once you've tried.
+17-0lessons/05-selecting-and-changing-elements/dom.html ADDED
@@ -0,0 +1,17 @@
1+<!doctype html>
2+<html lang="en">
3+<head><meta charset="utf-8"><title>DOM practice</title></head>
4+<body>
5+ <h1 id="title">Shopping list</h1>
6+ <ul id="list"><li>milk</li><li>eggs</li></ul>
7+ <script>
8+ const title = document.querySelector("#title");
9+ title.textContent = "Groceries";
10+ title.classList.add("highlight");
11+
12+ const item = document.createElement("li");
13+ item.textContent = "bread";
14+ document.querySelector("#list").append(item);
15+ </script>
16+</body>
17+</html>
+5-0lessons/05-selecting-and-changing-elements/exercises.md ADDED
@@ -0,0 +1,5 @@
1+# Exercises: lesson 5
2+
3+1. Combine this lesson with the previous one: use something from both in a small program of your own.
4+2. Add a check that prints a warning when a result looks wrong (negative, empty, too big).
5+3. Explain the example to someone who hasn't taken the course. Which part was hardest to explain?