Often I see javascript code where event handlers (like onmousemove) are assigned dynamically.
Example:
document.getElementById('foo').onmousemove = function(e)
{ /* do some stuff with event e */ }
Apparently this ‘e’ parameter is some kind of event object. Where does that come from, as in: who or what defines what this ‘e’ parameter is when the function is called, and can I also do this in static html?
I mean like this:
<div id='foo' onmousemove='Bla(e)'> ... </div>
What should I fill in for ‘e’ to get that same event thing? And can I also combine that with more parameters, like
<div id='foo' onmousemove='Bla(this,e,4)'> ... </div>
where e is, again, supposed to be the event object?
The event object is stored in
window.eventinside of any event handler, so you do not need to worry about your handler conforming to accepting it as a parameter.In your second and third examples, the
eparameter will be passed as undefined because no variableeexists in that scope (unless you have a globale).