PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Other / Miscellaneous/The Trade Desk

Add a click listener to a button

Last updated: Mar 29, 2026

Quick Overview

Add a click listener to a button evaluates requirements, assumptions, structured reasoning, trade-offs, and verification in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

  • easy
  • The Trade Desk
  • Other / Miscellaneous
  • Software Engineer

Add a click listener to a button

Company: The Trade Desk

Role: Software Engineer

Category: Other / Miscellaneous

Difficulty: easy

Interview Round: Technical Screen

Given an HTML page that includes a button with the id 'my-button', write JavaScript to add a click event listener so that when the button is clicked, the button's text content is logged to the console. Use document.querySelector and addEventListener. Briefly explain what e.target refers to in this context.

Quick Answer: Add a click listener to a button evaluates requirements, assumptions, structured reasoning, trade-offs, and verification in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

|Home/Other / Miscellaneous/The Trade Desk

Add a click listener to a button

The Trade Desk logo
The Trade Desk
Jul 26, 2025, 12:00 AM
easySoftware EngineerTechnical ScreenOther / Miscellaneous
7
0

Add a click listener to a button

JavaScript: Add a Click Listener to Log Button Text

Context

Assume your page contains a button element like:

<button id="my-button">Click me</button>

Task

  • Use document.querySelector and addEventListener to 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.target refers to in the click handler.

Constraints & Assumptions

  • Preserve the scope, facts, inputs, and requested outputs from the prompt above.
  • If the prompt leaves a detail unspecified, state a reasonable assumption before relying on it.
  • Keep the answer interview-ready: concise enough to present, but concrete enough to implement or evaluate.

Clarifying Questions to Ask

  • Clarify the goal, inputs, constraints, stakeholders, and success criteria.
  • State assumptions before using them.
  • Keep the answer grounded in the prompt rather than adding outside facts.

What a Strong Answer Covers

  • A structured framing of the problem and constraints.
  • A concrete approach with trade-offs and edge cases.
  • A way to validate the answer and communicate the recommendation.

Follow-up Questions

  • What assumption is most important to validate first?
  • What could make the answer fail in practice?
  • How would you explain the result to a non-technical stakeholder?
Loading comments...

Browse More Questions

More Other / Miscellaneous•More The Trade Desk•More Software Engineer•The Trade Desk Software Engineer•The Trade Desk Other / Miscellaneous•Software Engineer Other / Miscellaneous

Write your answer

Your first approved answer each day earns 20 XP.

Sign in to write your answer.
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.