# Event handling
TIP
declare function on(eventNames: string, listener: EventListener): this;
declare function off(eventNames: string, listener: EventListener): this;
declare function trigger(eventNames: string, options?: Object): this;
Each method accepts a space-separated string for event names.
This API can be used w/ custom event names (as trigger()
allows custom events).
# LightqueryCollection#on
Attach an event listener to multiple events. Note that this
will be bound to the element in the listener,
thus try to avoid the use of arrow functions.
const onClick = function(e){
e.preventDefault();
doStuffWith(this);
};
µ(/**/).on("click touch", onClick); //-> this LightqueryCollection
# LightqueryCollection#off
Detach an event listener for multiple events. Note that the listener must be the exact same function.
µ(/**/).off("click touch", onClick); //-> this LightqueryCollection
# LightqueryCollection#trigger
Trigger multiple events. Note that you can pass custom options.
These options will be on the event instance. There will always be a target
property that corresponds to the element on
which the event is triggered.
µ(/**/).trigger("click"); //-> this LightqueryCollection
TIP
This method uses the Custom events API.