PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Other / Miscellaneous/The Trade Desk

Add a click listener to a button

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of DOM event handling and the event object in JavaScript, including use of document.querySelector, addEventListener, and the meaning of e.target.

  • 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: This question evaluates understanding of DOM event handling and the event object in JavaScript, including use of document.querySelector, addEventListener, and the meaning of e.target.

The Trade Desk logo
The Trade Desk
Jul 26, 2025, 12:00 AM
Software Engineer
Technical Screen
Other / Miscellaneous
5
0

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.

Solution

Show

Comments (0)

Sign in to leave a comment

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
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL 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.