The HTML DOM object model defines an Event
object with a target property.
Looking at MSDN, Microsoft documents a target property. They also document srcElem
The problem here was not that you didn’t use addEventListener()
(because old-school .onclick
-assignment works as well). The problem was that divClick
got this
(which equals eventobj.target
), but you want the entire eventobj
.
In the following two cases you only get eventobj.target
under the name of this
and you have no access to the arguments passed to the onclick-handler.
document.getElementById("xyz").onclick = function () { divClick(this); };
You get the entire eventobj
as normal parameter with the following line:
document.getElementById("xyz").onclick = divClick;
This is how an event is launched on the xyz element in IE9+ and other browsers:
document.getElementById("xyz").onclick(eventobj)