Question 9
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 = [];
document.getElementById("outer").addEventListener("click", () => order.push("outer"));
document.getElementById("inner").addEventListener("click", (e) => {
order.push("inner");
e.stopPropagation();
});
document.getElementById("inner").addEventListener("click", () => order.push("inner 2"));
document.getElementById("btn").click();
console.log(order.join(", "));
- A inner
- B inner, inner 2 Correct
- C inner, inner 2, outer
- D inner, outer
Correct Answer: Option B
stopPropagation stops the event from reaching outer, but other listeners on the same element still run (that would need stopImmediatePropagation).
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!