To the good people who downvoted because it's been asked before: my question was not about the implicit event parameter. I had no idea. The event parameter was the answer, not the question.
function myEventHandler() {
var eventSrcType=(event.srcElement) ? event.srcElement.type : 'type undefined';
alert(eventSrcType);
}
The function gets called when the user clicks an image ("onclick"), e.g
<a href="javascript:void(0)" onclick="myEventHandler();">
Apparently there's something wrong with the assignment, because the alert
is never executed. What's wrong here?
(I tried window.event
, but Dreamweaver doesn't hint event
as a member of window
. Anyway, it doesn't work either)
edit
All answers hint at the implicitly passed event
. So I added that as the function's argument (calling without argument),
function myEventHandler(event) {
var eventSrcType=(event.srcElement) ? event.srcElement.type : 'type undefined';
alert(eventSrcType);
}
But I still don't get an alert.
Passing this
as argument shows "type undefined", but I expect the anchor type here.