Sign in to track progress, unlock prep layers, and browse your pipeline.Sign in
Add a click listener to a button
Context
Assume your page contains a button element like:
<button id="my-button">Click me</button>
Task
- Use
document.querySelectorandaddEventListenerto add a click handler to the button with id "my-button". - When the button is clicked, log the button's text content to the console.
- Briefly explain what
e.targetrefers to in the click handler.
AI interview prep
Core dilemma
Ensuring robust and performant client-side event handling, understanding the lifecycle and potential pitfalls of DOM manipulation and event listeners in a dynamic web environment.
Mid-level signals3
Senior signals3
Red flags3
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Add a click listener to a button
Context
Assume your page contains a button element like:
<button id="my-button">Click me</button>
Task
- Use
document.querySelectorandaddEventListenerto add a click handler to the button with id "my-button". - When the button is clicked, log the button's text content to the console.
- Briefly explain what
e.targetrefers to in the click handler.