DOM and Events
Make pages interactive by reading and changing the DOM.
Make web pages respond to people. You will find elements with CSS selectors and walk the DOM tree, change text, attributes, classes and whole lists of elements without opening the door to XSS, listen for clicks, keys and form events, and use bubbling, delegation and preventDefault on purpose. Then you will validate forms with inline, accessible errors, debounce a live search, and build the interactive components real products need: a disclosure, a modal dialog that returns focus, keyboard operable tabs and live region announcements. Every exercise is graded by what the page really does when it is clicked, typed into and tabbed through, and every widget passes the axe accessibility engine. The course ends with a todo list, a confirm dialog, a signup form and a live filtered list.
What you will learn
- DOM queries and traversal
- Changing the page safely
- Events and delegation
- Forms and validation with JavaScript
- Accessible interactive components
Lessons
- 1
The DOM Tree
window, document and navigator, the tree of nodes and how to walk it, querySelector, querySelectorAll and getElementById, static NodeLists and live collections, and when a script can see the page: defer and DOMContentLoaded.
11 exercises
- 2
Changing the Page
textContent and innerHTML and why user data in innerHTML is XSS, creating, appending, removing and replacing elements, attributes, properties and dataset, classList instead of inline styles, and rendering a list from an array with a template.
10 exercises
- 3
Events
addEventListener and handler properties, why inline onclick is avoided, the event object, removing listeners and once, bubbling and capture, target and currentTarget, event delegation, and preventDefault versus stopPropagation.
12 exercises
- 4
Forms with JavaScript
Handling submit, reading fields with FormData, the Constraint Validation API with checkValidity and setCustomValidity, inline errors with aria-invalid and aria-describedby, input versus change, and a debounced live search.
10 exercises
- 5
Accessible Interactive Components
A disclosure with aria-expanded, a modal dialog with showModal that returns focus, tabs with roving tabindex and arrow keys, live region announcements, and events that work for mouse, touch and keyboard alike.
12 exercises
- 6
Putting It Together
Four small apps built from everything in the course: a todo list with delegation and filters, an accessible confirm dialog, a validated signup form with inline errors, and a live filtered list.
8 exercises
How you practice
You practice in the browser and every exercise gives you feedback right away. This course uses these formats:
- Code exercise: 22
- Fix the bug: 18
- Predict the output: 9
- Fill in the blank: 5
- Multiple choice: 4
- Type the answer: 3
- Spot the bug: 1
- Select all that apply: 1
Aligned to
- Specialized Platform Development
- SPD-WebWeb Platforms
- Human-Computer Interaction
- HCI-AccessibilityAccessibility and Inclusive Design
- Foundations of Programming Languages
- FPL-Event-DrivenEvent-Driven and Reactive Programming
- Basics of JavaScript and Computer Programming
- 1.3.1Explain client-side execution of JavaScript code
- JavaScript fundamentals
- 6.9DOM scripting
- 6.10Events
- Accessibility
- 7.3Accessible JavaScript
- 7.5WAI-ARIA basics
- Operable
- 2.1.1Keyboard
- 2.1.2No Keyboard Trap
- 2.4.3Focus Order
- Understandable
- 3.2.1On Focus
- 3.2.2On Input
- 3.3.1Error Identification
- 3.3.3Error Suggestion
- Robust
- 4.1.2Name, Role, Value
- 4.1.3Status Messages
Proto Node Labs is not affiliated with or endorsed by ACM / IEEE-CS / AAAI, JS Institute, Mozilla and W3C. Exam names are trademarks of their owners.