Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

JavaScript Dictionary

  1. Home
  2. JavaScript Dictionary
  3. event.target / currentTarget

event.target / currentTarget Since: DOM Level 2(2000)

Properties of the event object that let you retrieve the HTML element where the event occurred and the type of the event. You access them from the event object passed to the callback function of an event listener.

Syntax

element.addEventListener("eventName", function(e) {
	e.target;        // The HTML element on which the event actually occurred
	e.currentTarget; // The HTML element to which the event listener is attached
	e.type;          // The type of the event
});

Property list

PropertyDescription
event.targetReturns the HTML element on which the event actually occurred. Because it returns the element that was directly clicked, clicking a child element returns that child element.
event.currentTargetReturns the HTML element to which the event listener is attached. Even when the event bubbles up, this always returns the element where the listener was registered.
event.typeReturns the type of the event that occurred as a string. Values such as click, input, and submit are returned.

Sample code

<div id="container">
	<button id="btn"><span>Click</span></button>
</div>
<p id="output"></p>
var container = document.querySelector("#container");
var output = document.querySelector("#output");

// Register a click event listener on container.
container.addEventListener("click", function(e) {
	// target is the HTML element that was actually clicked.
	console.log("target: " + e.target.tagName);

	// currentTarget is the HTML element where the listener is registered.
	console.log("currentTarget: " + e.currentTarget.tagName);

	// type is the kind of event that occurred.
	console.log("type: " + e.type);

	output.textContent = "target=" + e.target.tagName + ", currentTarget=" + e.currentTarget.tagName;
});

Output

When you click the <span> inside the button, target is the <span> that was actually clicked, while currentTarget is the <div> where the listener is registered.

// When <span> is clicked
target: SPAN            // The HTML element that was actually clicked
currentTarget: DIV      // The HTML element where the listener is registered
type: click             // The type of event
<p id="output">target=SPAN, currentTarget=DIV</p>

Notes

The difference between event.target and event.currentTarget becomes clear when you understand event bubbling — the propagation of an event from a child element up to its parent elements. When a child element is clicked, the event travels from the child up to its parents. At that point, event.target refers to the child element that was actually clicked, while event.currentTarget refers to the parent element where the listener is registered.

In the event delegation pattern, you register a listener on a parent element and use event.target to identify which child element was clicked and branch your logic accordingly. This technique becomes even more powerful when combined with element.closest(), since it also works with dynamically added HTML elements.

event.type is useful when you want a single function to handle multiple events. For example, you can handle both mouseover and mouseout in the same function and branch your logic based on the value of event.type.

Browser compatibility

Chrome Chrome
49+
Supported in all versions
Firefox Firefox
57+
Supported in all versions
Safari Safari
18+
Supported in all versions
Edge Edge
80+
11 or earlier ×
IE IE
11+
8 or earlier ×
Opera Opera
48+
6 or earlier ×
iOS Safari iOS Safari
18+
Supported in all versions
Android Browser Android Browser
37+
4 or earlier ×
Chrome Android Chrome Android
36+
17 or earlier ×
Firefox Android Firefox Android
79+
3 or earlier ×

If you find any errors or copyright issues, please .