gloriaJun / til

Lessoned Learned
3 stars 0 forks source link

event.target vs. event.currentTarget #23

Open gloriaJun opened 5 years ago

gloriaJun commented 5 years ago

target

The DOM element on the lefthand side of the call that triggered this event

currentTarget

The EventTarget whose EventListeners are currently being processed. As the event capturing and bubbling occurs this value changes.

Example

<div onclick="checkTarget();">
  <span>test</span>
</div>
function checkTarget(event) {
  console.log(event.currentTarget);  // return 'div' DOM
  console.log(event.target); // return 'span' DOM
}

References