CodePark/ questions / DOM & events
START PRACTICINGPRACTICE
Frontend question · JavaScript › DOM & events

A single click listener is attached to a <ul>. The user clicks an <li> inside it. Inside the listener, what are event.target and event.currentTarget?

target is the <li>, currentTarget is the <ul>

target is the <li> and currentTarget is the <ul>. target is the element where the event started, the clicked <li>. It does not change as the event bubbles up. currentTarget is the element whose listener is running now, here the <ul>. Event delegation depends on this difference.

The tempting option "Both are the
<ul>" is wrong because target stays the clicked element, even when the listener is on a parent.