Here w3school talks about the event object:
Events are actions that JavaScript can detect, and the event object provides information about the event that occurred.
Sometimes we want to execute JavaScript when an event occurs, such as when the user clicks a button.
You can handle events using:
node.onclick = function(e) { // here you can handle event. e is an object. // It has some usefull properties like target. e.target refers to node }
However, Internet Explorer does not pass the event to the handler. Instead, you can use the window.event object, which is updated immediately after the event fires. So the crossbrowser method for handling events:
node.onclick = function(e) { e = e || window.event; // also there is no e.target property in IE. // instead IE uses window.event.srcElement var target = e.target || e.srcElement; // Now target refers to node. And you can, for example, modify node: target.style.backgroundColor = '#f00'; }
Molecular man
source share