examples and exercises to practice creating and manipulating dom elements.
in each exercise or example, there is a target div and a replication div. the goal is to write a small JS script that makes the replication look like the target.
be very aware of the difference between source HTML code and the live DOM! In each example what you see in the inspector does not match what you saw in the source HTML. This is because the HTML describes the initial DOM, but that DOM will change after your script is executed! to revisit the source HTML you can type ctr-u
and the source code will open in a new tab.
Examples: creating DOM elements
Examples: modifying elements
- remove a child
ul
tool
- update
ul
: manual - update
ul
: loop - update
ul
: forEach - nested children 1
- nested children 2
- clone a node
Exercises:
Some helpful resources