(event)?


#1

Why event in brackets?

$(’.product-photo’).on(‘mouseenter’, (event) => {
$(event.currentTarget).addClass(‘photo-active’)
}).on(‘mouseleave’, event => {
$(event.currentTarget).removeClass(‘photo-active’)
})


#2

That is the nickname we give the EventObject which is returned by the listener. From it we can obtain information with respect to the type of event, the event target, and other useful information as needs be.

Here is an example of the kind of information stored in the EventObject…

originalEvent: [object KeyboardEvent]
type: keydown
timeStamp: 11750.34850007065
jQuery171009694749273172287: true
keyCode: 67
key: c
charCode: 0
char: undefined
which: 67
view: [object Window]
target: [object HTMLBodyElement]
shiftKey: false
relatedTarget: undefined
metaKey: false
eventPhase: 3
currentTarget: [object HTMLDocument]
ctrlKey: true
cancelable: true
bubbles: true
altKey: false
srcElement: undefined
relatedNode: undefined
attrName: undefined
attrChange: undefined
delegateTarget: [object HTMLDocument]
data: null
handleObj: [object Object]

Mouse events demo


#3

Why was the bracket only on the first event but not the second event? (Furthermore, from the instruction it seems bracket was not part of the expected syntax…)

I also noticed in the code in the review section, there is no bracket in either “event” s…


#4

When there is only one parameter, the parens are optional. Either way is valid.