Events
Two ways to interact:
generalized
addEventListener()
Ex:
e.addEventListener('click', handleClick);
specific on- handlers
only one on-event handler for a given event
Ex:
e.onclick = handleClick
Call with
e.onclick()
Print current function
e.onclick.toString()
load | click | blur | error | focus | scroll | mouseover | keydown
Event handlers take an event parameter
Remove Listener
Must have same arguments, so can't do anonoymous ft
Just overwrite ez
Only trigger event on parent, not children
HTML
mouseover => enters the div or any of its child(div then child is twice triggered)
mouseenter => only when div first entered
mouseleave => only when div left
onmousemove => any movement over the div element.
Pointer Events CanIUse
Allows varius inputs like touchscreens, pens, etc
Supported in most browsers now even IE11
In react, onPointerDown or regular pointerdown. For backwards compatability, touch/pen events fire mouse events but a little late and a little unreliably
Custom Events
Use detail to hold extra information
Last updated