// Listen for events on each element of this collection
eles.on(events: string, callback?: EventHandler<NodeData, EdgeData>): thisListen for events on each element of this collection. The handler is bound per element, and keeps firing across slot compaction — listeners repair with their elements rather than going stale.
Events bubble from an element through its compound ancestors to the core, with stopPropagation() honoured.
Any name registers, as on the core and for the same reason — custom events are supported API (ele.emit( 'foo')), so names cannot be gated. A name the library never emits fires only when your application emits it. Names match literally: 'data.ns' is distinct from 'data'. Raw mouse/touch names and vmouse* aliases are not emitted by the library. See Core#on.
| Name | Description |
|---|---|
events: string | one or more space-separated event names |
callback: EventHandler<NodeData, EdgeData>? | the handler |
thisthis collection, for chaining
Example
const seen = [];const handler = event => seen.push(event.type);cy.getElementById('a').on('example', handler);cy.getElementById('a').emit('example');cy.getElementById('a').off('example', handler);console.log(seen); // ['example']Also spelled eles.addListener.