If I have event handlers registered inline in my markup (even though it's deprecated) like
span id="..." onclick="foo(p1,p2,p3)"
how do I access the "event" object in the event handler function foo
? Is changing the above to
span id="..." onclick="foo(event,p1,p2,p3)"
and then using it in foo
like:
function foo(e,p1,p2,p3)
{
if (!e) e = window.event;
}
the correct way to do it? I couldn't find any documentation on this, so I'm hesitant to rely on it. Does the first parameter in an inline event handler always represent the event object when named as such in the onclick=...
attribute? Is this behavior consistent across browsers or is it risky to use? And if the event object is not explicitly named, are the other parameters considered normal and the event object not passed?
What are your thoughts on this?