Skip to content

eles.on(events, callback?)

eles.on — Collection > Events. Cytoscape.js signatures, parameters and return contract.

eles.on — Collection › Events

Preview · Collection › Events

Read in the complete API reference · All API members

// Listen for events on each element of this collection
eles.on(events: string, callback?: EventHandler<NodeData, EdgeData>): this

Listen 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.

Parameters
NameDescription
events: string

one or more space-separated event names

callback: EventHandler<NodeData, EdgeData>?

the handler

Returns this

this 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']

Example graph and handle setup

Also spelled eles.addListener.