이 문서는 아직 자원 봉사자들이 한국어로 번역하지 않았습니다. 함께 해서 번역을 마치도록 도와 주세요!
A reference to the object that dispatched the event. It is different from event.currentTarget
when the event handler is called during the bubbling or capturing phase of the event.
Syntax
theTarget = event.target
Example
The event.target
property can be used in order to implement event delegation.
// Assuming there is a 'list' variable containing an instance of an HTML ul element. function hide(e) { // Unless list items are separated by a margin, e.target should be different than e.currentTarget e.target.style.visibility = 'hidden'; } list.addEventListener('click', hide, false); // If some element (<li> element or a link within an <li> element for instance) is clicked, it will disappear. // It only requires a single listener to do that
Specifications
Specification | Status | Comment |
---|---|---|
DOM The definition of 'Event.target' in that specification. |
Living Standard | |
DOM4 The definition of 'Event.target' in that specification. |
Recommendation | |
Document Object Model (DOM) Level 2 Events Specification The definition of 'Event.target' in that specification. |
Recommendation | Initial definition |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Compatibility notes
On IE 6-8 the event model is different. Event listeners are attached with the non-standard EventTarget.attachEvent
method. In this model, the event object has a Event.srcElement
property, instead of the target
property, and it has the same semantics as event.target
.
function hide(e) { // Support IE6-8 var target = e.target || e.srcElement; target.style.visibility = 'hidden'; }
See also
문서 태그 및 공헌자
태그:
이 페이지의 공헌자:
cvrebert,
maybe,
fscholz,
Sebastianz,
jpmedley,
teoli,
Sheppy,
alexilyaev,
MHasan,
Foo,
kscarfone,
rashidtherash,
Kartik_Chadha,
Procoffeev,
Matej Lednar,
dbruant,
Nickolay,
Hamstersoup,
Jabez,
Ptak82,
Dria,
JesseW
최종 변경:
cvrebert,