The HTML DOM object model defines an Event
object with a target
property.
Looking at MSDN, Microsoft documents a target
property. They also document srcElement
as an alias of target
from earlier versions of Internet Explorer:
The target property is similar to srcElement in Windows Internet Explorer 8 and earlier versions.
So here i am in Internet Explorer, sitting at a click
breakpoint:
<div class="day" onclick="divClick(this)">
function divClick(sender)
{
var divCell = sender;
And at the F12 Tools console i can ask for the global event
object:
>> event
{
actionURL : "",
altKey : false,
altLeft : false,
behaviorCookie : 0,
behaviorPart : 0,
bookmarks : null,
boundElements : {...},
button : 0,
buttonID : 0,
cancelBubble : false
...
}
And i can ask for the event.srcElement
object:
>> event.srcElement
{
align : "",
noWrap : false,
dataFld : "",
dataFormatAs : "",
dataSrc : "",
currentStyle : {...},
runtimeStyle : {...},
accessKey : "",
className : "header",
contentEditable : "inherit"
...
}
But event.target
is empty:
>> event.target
And if i watch event
, there is no target
property:
So how do i access the target
property of an event
object in Internet Explorer (9 (Document Mode: IE9 Standards (Browser Mode: IE9)))?
If you want to use event.target
in IE9, you'll need to use addEventListener()
-method to assign eventhandler to the element.
<div id="day" class="day"></div>
document.getElementById('day').addEventListener('click',divClick,false);
function divClick(e){
alert(e.target);
divCell=this;
:
}
In divClick()
you can refer day
simply using keyword this
. Argument e
contains a reference to the event-object itself.
BTW, in MSDN you can find maybe more suitable IE-documentation for Web development instead of Windows development.