The currentTarget
read-only property of the Event
interface identifies the current target for the event, as the event traverses the DOM. It always refers to the element to which the event handler has been attached, as opposed to Event.target
, which identifies the element on which the event occurred.
Syntax
var currentEventTarget = event.currentTarget;
Value
Example
Event.currentTarget
is interesting to use when attaching the same event handler to several elements.
function hide(e){ e.currentTarget.style.visibility = 'hidden'; console.log(e.currentTarget); // When this function is used as an event handler: this === e.currentTarget } var ps = document.getElementsByTagName('p'); for(var i = 0; i < ps.length; i++){ // Console: print the clicked <p> element ps[i].addEventListener('click', hide, false); } // Console: print <body> document.body.addEventListener('click', hide, false); // Click around and make paragraphs disappear
Specifications
Specification | Status | Comment |
---|---|---|
DOM The definition of 'Event.currentTarget' in that specification. |
Living Standard | |
DOM4 The definition of 'Event.currentTarget' in that specification. |
Obsolete | |
Document Object Model (DOM) Level 3 Events Specification The definition of 'current event target' in that specification. |
Obsolete | |
Document Object Model (DOM) Level 2 Events Specification The definition of 'Event.currentTarget' in that specification. |
Obsolete | Initial definition |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Basic support | Chrome Full support Yes | Edge Full support Yes | Firefox Full support Yes | IE
Full support
9
| Opera Full support Yes | Safari Full support 10 | WebView Android Full support Yes | Chrome Android Full support Yes | Edge Mobile Full support Yes | Firefox Android Full support Yes | Opera Android Full support Yes | Safari iOS Full support 10 | Samsung Internet Android ? |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown
- See implementation notes.
- See implementation notes.
See also
Document Tags and Contributors
Tags:
Contributors to this page:
mfluehr,
fscholz,
329530588,
thomasuebel,
erikadoyle,
bblack,
cvrebert,
Sebastianz,
teoli,
Cobra,
Sheppy,
dbruant,
ziyunfei,
DavidWalsh,
evilpie,
Sevenspade,
shiawuen,
Matej Lednar,
Nickolay,
Hamstersoup,
Jabez,
Ptak82,
Dria,
JesseW
Last updated by:
mfluehr,