After spending so much time in jQuery, I’m rusty on my old fashioned JS…
The question: When attaching an event to an object that you want to trigger a function, how do you pass the event to said function?
Example function:
myFunction(e){
...
}
Example event attachment:
document.getElementById('blargh').onkeypress = function(){myfunction([what do I put here to pass the event?])};
Make the handler accept a parameter, say
event, and pass it to your function:The event handler always gets the current event passed as parameter… in the W3C model.
For IE you have to get the parameter via
window.event. Thus, in the function you can write something like: