currentTarget property

Gets the event target that is currently being processed.

Document Object Model (DOM) Level 3 Events Specification, Section 4.1Internet Explorer 9

 

Syntax

JavaScript

p = object.currentTarget

 

Property values

Type: Object

The current target of the event.

Standards information

Remarks

The target property returns the element that originally received an event. However, the currentTarget property returns the element that the event handlers are being processed for during the capturing and bubbling phases. At event phase AT_TARGET, the currentTarget and target objects are the same object.

In Windows Internet Explorer 8 and earlier versions, the event object does not provide access to the current event target. For the equivalent functionality, specify the this keyword as an argument to the event handler, as the following code example shows.


<button id="target" onclick="myHandler(event, this);">...</button>
function myHandler(evt, elem) {
    alert(elem.id);
} 

Alternatively, if the event handler is set with an event property, the current target is set as the this keyword when the event handler is invoked, as the following code example shows.


document.getElementById('target').onclick = myHandler;
function myHandler(evt) {
    alert(this.id);
} 

If you use attachEvent, you cannot access the current event target in the event handler.

See also

BeforeUnloadEvent
CompositionEvent
CustomEvent
DragEvent
Event
FocusEvent
KeyboardEvent
MessageEvent
MouseEvent
MouseWheelEvent
MSSiteModeEvent
MutationEvent
StorageEvent
SVGZoomEvent
TextEvent
UIEvent
eventPhase

 

 

Show:
© 2014 Microsoft