InterviewStack.io LogoInterviewStack.io

DOM Manipulation and Browser APIs Questions

Programming the browser platform: the Document Object Model, traversal and mutation, event handling and the event model, and the wider set of browser and web-platform APIs. Covers manipulating rendered pages and reasoning about browser internals without relying on a framework. A core frontend interview surface.

MediumTechnical
91 practiced

Implement event delegation: Given a <ul id="list"> whose <li> items are added dynamically, write a vanilla JavaScript handler attached to the <ul> that detects clicks on any <li>, reads its data-id attribute, and logs the id. Include robust checks to avoid handling clicks from unrelated nested controls.

HardTechnical
77 practiced

You are building a reusable UI library in vanilla JS that creates components and attaches event listeners. Describe patterns to ensure components clean up event listeners and DOM references when removed, considering both explicit teardown APIs and automatic detection. Mention trade-offs and integration points for frameworks.

EasyTechnical
94 practiced

Given the following HTML:

<ul id="menu"> <li class="item" data-id="1">Home</li> <li class="item" data-id="2">About</li> <li class="item" data-id="3">Contact</li> </ul>

Write three JavaScript statements that: (1) select the <ul> by id, (2) select all <li> elements as a NodeList, and (3) select the second <li> using a CSS selector. After the code, briefly explain when you would prefer querySelector/querySelectorAll over getElementById/getElementsByClassName in real code.

EasyTechnical
86 practiced

List three best practices to make non-semantic elements (e.g., a <div> acting as a button) accessible to keyboard users. For each practice, explain the rationale and a concise code example or attribute to use.

EasyTechnical
82 practiced

Describe the difference between element.setAttribute('value', value) and element.value when updating an input element. Also explain when you should use data-* attributes via element.dataset versus setAttribute for custom metadata.

Unlock Full Question Bank

Get access to all 37 DOM Manipulation and Browser APIs interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.