The event.target property
event.target points at the element on which the event actually happened, that is, the source of the event. It is one of the most useful properties of the event object: it tells you exactly where the user clicked, what they typed, or which action they triggered.
Theory
TL;DR
event.targetis the DOM element where the event originated.- It does not necessarily match the element the handler is attached to.
- The element holding the handler is available as
event.currentTarget. - In both cases the value is a DOM element (
HTMLElement). - The main use case is event delegation: one listener instead of hundreds.
- In forms,
event.target.nameandevent.target.valuegive you the changed field and its new value.
Quick example
element.addEventListener('click', function (event) {
console.log(event.target);
});The property is available inside any handler that receives the event object.
What event.target is
event.targetis the DOM element on which the event first happened: a click, an input, a hover and so on.
<div id="container">
<button id="btn">Click me</button>
</div>document.querySelector('#container').addEventListener('click', (event) => {
console.log('event.target:', event.target);
});If you click the button, the console shows:
event.target: <button id="btn">Click me</button>So target is the element that was clicked, not the one the handler hangs on (#container). The event bubbles up from the button to the container, but the target property does not change along the way.
target versus currentTarget
| Property | What it shows |
|---|---|
event.target | the element where the event happened (the inner one) |
event.currentTarget | the element the handler is attached to |
document.querySelector('#container').addEventListener('click', (event) => {
console.log('target:', event.target);
console.log('currentTarget:', event.currentTarget);
});If the click lands on the <button> inside the container:
target: <button>
currentTarget: <div id="container">Event delegation
This is the most common use of event.target.
<ul id="list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>document.querySelector('#list').addEventListener('click', (event) => {
if (event.target.tagName === 'LI') {
console.log(`Clicked on item: ${event.target.textContent}`);
}
});Here we attached one handler to the whole list and check inside which <li> was actually clicked. This is called event delegation: it saves memory and speeds things up, especially when there are many items or they appear dynamically.
Working with forms
form.addEventListener('input', (event) => {
console.log('Changed element:', event.target.name);
console.log('New value:', event.target.value);
});This lets you track changes in every form field through one handler, without subscribing to each <input> separately.
Summary
| Property | What it does |
|---|---|
event.target | the element where the event happened |
event.currentTarget | the element the handler is attached to |
| Used for | delegation, checking the source of an event, reaching the clicked element |
| Data type | a DOM element (HTMLElement) |
Conclusion:
event.targetis the true source of an event. With it you can tell precisely where the user clicked, typed text, or triggered some other action.
Common mistakes
- Confusing
targetwithcurrentTargetand trying to read the container'sdatasetoffevent.target. - Forgetting that
currentTargetis available inside the handler but becomesnullonce the handler returns: capture the value right away. - Checking only
event.target.tagNamein delegation when the<li>has nested elements: a click on a<span>yieldsSPAN.event.target.closest('li')is safer. - Assuming
event.targetis always an element: for non-DOM events (anXMLHttpRequest, for instance) it is a different object. - Using
thisinstead ofcurrentTargetinside an arrow function, wherethisdoes not point at the element.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.