Question 7
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 = [];
for (const id of ["outer", "inner", "btn"]) {
document.getElementById(id).addEventListener("click", () => order.push(id));
}
document.getElementById("btn").click();
console.log(order.join(" > "));
- A outer > inner > btn
- B btn > inner > outer Correct
- C btn
- D inner > btn > outer
Correct Answer: Option B
Bubbling listeners run from the target up through its ancestors, whatever order they were added in.
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!