What's the difference between event.target and event.currentTarget?
Short answer
event.target is the actual element that originated the event (e.g., the specific clicked); event.currentTarget is the element the listener is currently attached to and executing on (e.g., the parent during bubbling).
Advertisement
AModel answer
event.target is the actual element that originated the event (e.g., the specific <li> clicked); event.currentTarget is the element the listener is currently attached to and executing on (e.g., the parent <ul> during bubbling).
list.addEventListener('click', (e) => {
console.log(e.target); // the <li> clicked
console.log(e.currentTarget); // the <ul> the listener is on
});Real-world example
Using target to identify which specific button in a toolbar was clicked, while currentTarget stays constant.
Likely follow-ups
- Does currentTarget change value during the bubbling phase?
Related topics