Free Online Flashcard Deck

6 The DOM and Browser Events Free Online FlashCards

Study 6 The DOM and Browser Events with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What does the DOM represent?

Back

The Document Object Model (DOM) represents a web document as a tree of nodes that JavaScript can inspect and update.

02
Front

How do `querySelector()` and `querySelectorAll()` differ?

Back

`document.querySelector()` returns the first matching element; `document.querySelectorAll()` returns a static collection of all matches.

03
Front

What does a DOM query return when no element matches?

Back

A query that finds no matching element returns `null`. Check the result before trying to use it.

04
Front

What happens when you set an element’s `textContent`?

Back

Setting an element’s `textContent` changes its text and replaces its child content with text.

05
Front

Why prefer `textContent` for user-supplied text?

Back

Prefer `textContent`: it treats the supplied value as text rather than parsing it as HTML markup.

06
Front

How can JavaScript change an element’s CSS classes?

Back

Use `classList.add()`, `classList.remove()`, or `classList.toggle()` to change an element’s CSS classes.

07
Front

How can JavaScript add a new element to the page?

Back

Create a node with `document.createElement()` and insert it into the page with a method such as `append()`.

08
Front

How does JavaScript register a response to an event?

Back

An event represents something that occurs, such as a click or key press. Register a listener with `addEventListener(type, callback)` to respond to it.

09
Front

What is the difference between `target` and `currentTarget`?

Back

`target` is where the event originated; `currentTarget` is the object whose listener is currently running.

10
Front

What are the main phases of event propagation?

Back

An event travels toward its target during capturing, runs target listeners at the target, then travels back through ancestors when it bubbles.

11
Front

What is event delegation?

Back

Event delegation uses a listener on a parent to handle events from descendants, often by relying on event bubbling.

12
Front

What does `event.preventDefault()` do?

Back

`event.preventDefault()` cancels a cancelable event’s default browser action, such as a form’s normal submission. It does not stop propagation.