Event target and currentTarget
Quick answer
An event object carries dispatch information. target identifies the target as exposed to the listener (it can be retargeted across shadow boundaries). currentTarget identifies the object whose listener is running. During ordinary bubbling from a nested element, these may differ. Outside listener execution, currentTarget is null.
Browser examples
Run each snippet in a fresh browser document. These are static code blocks; ByteMind browser execution is not verified. Storage examples require a test origin.
const p=document.createElement("div"),b=document.createElement("button");p.append(b);p.addEventListener("click",e=>console.log(e.target.tagName,e.currentTarget.tagName));b.click();Expected console output:
BUTTON DIVThe nested button is the target and the parent is the listener owner.
const b=document.createElement("button");let saved;b.addEventListener("click",e=>{saved=e;console.log(e.currentTarget===b);});b.click();console.log(saved.currentTarget===null);Expected console output:
truetrueDispatch clears currentTarget after the listener calls.
Common mistake
Do not assume event.target is the element on which you registered the listener. Copy any needed currentTarget before awaiting asynchronous work.
Practice
Click a nested span in a button and compare target and currentTarget in the button listener.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Event target and currentTarget — Knowledge Check
Apply the concept and predict the browser example behavior.
Which property identifies the listener owner during callback execution?
What is currentTarget after dispatch completes?
What should an async listener save before await if it needs the listener owner later?
What is the exact console output in Event target and currentTarget example 1?
const p=document.createElement("div"),b=document.createElement("button");p.append(b);p.addEventListener("click",e=>console.log(e.target.tagName,e.currentTarget.tagName));b.click();What is the exact console output in Event target and currentTarget example 2?
const b=document.createElement("button");let saved;b.addEventListener("click",e=>{saved=e;console.log(e.currentTarget===b);});b.click();console.log(saved.currentTarget===null);