- DOM: the browser’s tree of objects representing the page; JavaScript reads and changes it.
- Select: getElementById, getElementsByClassName, querySelector (first match), querySelectorAll (NodeList of all matches).
🎯 How this can come up · 1 question
document.querySelector(".item") returns:
Correct: The first element with class item.
- element.style.color = "red" sets inline style; better: element.classList.add/remove/toggle.
- innerHTML parses HTML (XSS risk with user input); textContent sets plain text safely.
🎯 How this can come up · 1 question
Which is safest for inserting user-typed text into the page?
Correct: textContent.
- Manipulation: createElement, appendChild / append, insertBefore, removeChild / remove, replaceChild.
- data-* attributes are read via element.dataset (data-user-id → dataset.userId).
- element.addEventListener("click", handler): many handlers per event, can be removed.
- Run DOM code after the page loads: DOMContentLoaded, or place the script at the end / use defer.
- The event object: e.target (the element clicked), e.type, e.preventDefault(), e.stopPropagation().
- Propagation: capture phase (down from the window) → target → bubbling phase (back up). Handlers run in the bubbling phase by default.
🎯 How this can come up · 1 question
By default, addEventListener handlers run during the:
Correct: Bubbling phase.
- Event delegation: one listener on a parent handles events from many children (using e.target), including children added later.
🎯 How this can come up · 1 question
Attaching one listener to a <ul> to handle clicks on all its <li> items is:
Correct: Event delegation.
- Types: mouse (click, mouseover), keyboard (keydown, keyup), form (submit, change, input, focus, blur), page (load, DOMContentLoaded).
- Handle the form’s submit event; call e.preventDefault() to stop sending invalid data.
- Regular expressions: /pattern/flags; ^ start, $ end, [a-z], \d digit, + one or more, * zero or more, {n} exactly n. regex.test(str).
🎯 How this can come up · 1 question
/^\d{4}$/ matches:
Correct: Exactly four digits.
No slides match this filter.































