DOM Manipulation and Browser APIs Questions

Programming the browser platform directly, without a framework: the Document Object Model, node selection and traversal (live vs static collections), content and attribute mutation (innerHTML vs textContent, attributes vs properties, DocumentFragment, cloning), the event model (capture, target, bubble, delegation, preventDefault vs stopPropagation, passive and once listeners, custom events, pointer, touch and keyboard events, drag and drop), and web-platform APIs (IntersectionObserver, MutationObserver, requestAnimationFrame and requestIdleCallback, Web Storage and IndexedDB and choosing between them, postMessage, BroadcastChannel and cross-tab coordination, fetch error handling with AbortController, Shadow DOM and Web Components). Includes keyboard and screen-reader operable vanilla widgets (modals, dropdowns, accordions, date pickers, carousels, data grids) with focus management and route-change focus, the DOM-level mechanics of reflow and layout thrash, listener and detached-node memory leaks, and writing vanilla JavaScript to build interactive widgets. Ground covered elsewhere: the event loop and promise mechanics, profiling-driven page speed work, form-validation and component-state patterns, application-level security, and rebuilding standard APIs from scratch.

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
93 practiced

Walk through the ways to select elements in the DOM and what each returns. Which results are live and which are static, and how could that difference bite you in a loop?

That is every published DOM Manipulation and Browser APIs question for Test Automation Engineer so far. Browse the other topics in this category, or practice this one interactively.