What does the DOM represent?
The Document Object Model (DOM) represents a web document as a tree of nodes that JavaScript can inspect and update.
Study 6 The DOM and Browser Events with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What does the DOM represent?
The Document Object Model (DOM) represents a web document as a tree of nodes that JavaScript can inspect and update.
How do `querySelector()` and `querySelectorAll()` differ?
`document.querySelector()` returns the first matching element; `document.querySelectorAll()` returns a static collection of all matches.
What does a DOM query return when no element matches?
A query that finds no matching element returns `null`. Check the result before trying to use it.
What happens when you set an element’s `textContent`?
Setting an element’s `textContent` changes its text and replaces its child content with text.
Why prefer `textContent` for user-supplied text?
Prefer `textContent`: it treats the supplied value as text rather than parsing it as HTML markup.
How can JavaScript change an element’s CSS classes?
Use `classList.add()`, `classList.remove()`, or `classList.toggle()` to change an element’s CSS classes.
How can JavaScript add a new element to the page?
Create a node with `document.createElement()` and insert it into the page with a method such as `append()`.
How does JavaScript register a response to an event?
An event represents something that occurs, such as a click or key press. Register a listener with `addEventListener(type, callback)` to respond to it.
What is the difference between `target` and `currentTarget`?
`target` is where the event originated; `currentTarget` is the object whose listener is currently running.
What are the main phases of event propagation?
An event travels toward its target during capturing, runs target listeners at the target, then travels back through ancestors when it bubbles.
What is event delegation?
Event delegation uses a listener on a parent to handle events from descendants, often by relying on event bubbling.
What does `event.preventDefault()` do?
`event.preventDefault()` cancels a cancelable event’s default browser action, such as a form’s normal submission. It does not stop propagation.