Question 8
Back to Exercise
The page contains this HTML:
<section id="outer">
<div id="inner"><button id="btn">Click</button></div>
</section>What does the following JavaScript code print when it runs on this page?
const order = [];
const on = (id, opts) => document.getElementById(id).addEventListener("click", () => order.push(id), opts);
on("btn");
on("inner");
on("outer", { capture: true });
document.getElementById("btn").click();
console.log(order.join(" > "));
- A outer > btn > inner Correct
- B btn > inner > outer
- C outer > inner > btn
- D btn > outer > inner
Correct Answer: Option A
The capturing listener on outer runs on the way down, before the target; the others run while bubbling.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!