Question Bank

JavaScript Cross-Browser Event Target: Two Approaches Quiz

Difficulty: Medium

Two seeded approaches to read the event target across browsers (event.target plus legacy event.srcElement, and a delegated table cell editor), plus two companions on currentTarget and composedPath.

Question Bank
/

JavaScript Cross-Browser Event Target: Two Approaches Quiz

JavaScript Cross-Browser Event Target: Two Approaches Quiz

Two seeded approaches to read the event target across browsers (event.target plus legacy event.srcElement, and a delegated table cell editor), plus two companions on currentTarget and composedPath.

Question Bank
Medium
JavaScript
4 questions
quiz
js-event-delegation
js-dom
js-language

340 views

7

Implement getEventTarget(e) that returns the originating DOM element across modern browsers AND legacy IE. Use the event.target || event.srcElement fallback, and normalize the window.event global as the very first step.

Examples

Example 1:

Input: a click event in Chrome
Output: the clicked element via event.target
Explanation: Modern browsers expose `target` directly; the `|| srcElement` branch is never taken.

Example 2:

Input: a click event in IE 8
Output: the clicked element via event.srcElement
Explanation: Old IE attached the event to `window.event` and exposed `srcElement` instead of `target`.