The element that triggered the event may be different from the one you associated the handler with, because the events create a bubble in the DOM tree .
So, if you want to get the identifier of the element to which the event handler is attached, you can do this easily with this.id ( this refers to the element).
But if you want to get the element in which the event occurred, you need to access it using event.target in browsers compatible with W3C, and event.srcElement in IE 8 and below.
I would not write a lot of JavaScript in the onXXXX HTML attributes. I would only pass the event object and put the code to retrieve the element in the handler (or in an additional function):
<div onlick="doWithThisElement(event)">
Then the handler will look like this:
function doWithThisElement(event) { event = event || window.event;
I suggest reading great articles on event handling at quirksmode.org .
Btw
<link onclick="doWithThisElement(id_of_this_element)" />
hardly makes sense ( <link> is an element that can only appear in <head> , binding an event handler (if at all possible) will have no effect).
Felix Kling Jul 04 2018-11-11T00: 00Z
source share