JavaScript alone knows nothing about pages. Every time a script reads a form field, adds a list item, reacts to a click or measures an element, it goes through the Document Object Model: the tree of objects the browser builds from your HTML.
This chapter starts with what the DOM is and what a change costs in rendering work, then tours the window object, node and element interfaces, HTML element objects, tree walkers and observers, and the event system.
The final sections cover patterns that keep DOM code fast and safe from cross-site scripting, how React 7,897 , Vue 5,482 and Solid 269,718 update the DOM for you, and where jQuery 561 , Alpine.js 208,904 and htmx 79,053 still fit.
What you will learn:
How the DOM tree, its interface hierarchy and the rendering pipeline relate
Using window, document, nodes, elements and HTML element objects
Traversing, observing and changing the tree efficiently
Handling, dispatching and customizing events
DOM performance patterns, XSS defense, jQuery and lightweight libraries
Sections
- The Document Object Model
- The Window Object
- Data Type Objects
- Event Target Objects
- HTMLElement Objects
- Processor Objects
- The Event Object
- Event Object Reference
- Binding Event Handlers
- Removing Event Handlers
- Handling Input Events
- Handling Document Events
- Handling Resource Events
- Handling Script Events
- Handling Browser Events
- Handling Smartphone Events
- Simulating Clicks
- Dispatching Events
- Customizing Events
- Preventing Default Behaviour
- Stopping Event Propagation
- Clicked Element's id
- DOM Patterns and Performance
- jQuery
- Lightweight DOM Libraries