Question 15
Back to Exercise
The page contains this HTML:
<div id="box"><button id="go">Go</button></div>What does the following JavaScript code print when it runs on this page?
let clicks = 0;
const original = document.getElementById("go");
original.addEventListener("click", () => clicks++);
document.getElementById("box").innerHTML += "<p>Added</p>";
const current = document.getElementById("go");
current.click();
console.log(clicks, current === original);
- A 1 true
- B 1 false
- C 0 true
- D 0 false Correct
Correct Answer: Option D
innerHTML += re-parses the whole content, so the button is a brand-new element without the listener.
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!