Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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

HRESULT value = object.get_currentTarget(IEventTarget** p);

Property values

Type: Object

The current target of the event.

Standards information

Remarks

The IDOMEvent::target property returns the element that originally received an event. However, the IDOMEvent::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 IDOMEvent::currentTarget and IDOMEvent::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 IHTMLElement2::attachEvent, you cannot access the current event target in the event handler.

See also

IDOMEvent::eventPhase

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.