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.
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
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 |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | Yes | Yes | Yes | 9
|
Yes | 10 |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | Yes | Yes | Yes | Yes | Yes | 10 | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget