The event
parameter in this function will give information about the event that triggered it when it is called by an event listener somewhere else in the code.
If nothing is passed as event
(so, it wasn’t called from a handler), it defaults to the global event
variable of the window.
Included in the information from the event is an attribute called either target
or srcElement
, depending on the browser being used (hence the check on line 6), which holds the element that was the target of the event.
This element is then modified in various ways using DOM manipulation functions on the last few lines of the block.
solved Why use event as a parameter in this JavaScript function?