Skip to content

API reference

cy.off — Core > Events. Cytoscape.js signatures, parameters and return contract.

cy.off — Core › Events

Preview · Core › Events

Read in the complete API reference · All API members

#cy.off(events, callback?)

// Remove a direct listener
cy.off(events: string, callback?: EventHandler<NodeData, EdgeData>): this

Stop listening. Removing a delegated handler takes the same ( events, predicate, handler) triple it was added with — predicates compare by function identity, so the predicate must be the same function object, not an equivalent one.

Parameters
NameDescription
events: string

one or more space-separated event names

callback: EventHandler<NodeData, EdgeData>?

the handler, when delegating

Returns this

this core, for chaining

Example

let count = 0;
const handler = () => count++;
cy.on('example', handler);
cy.off('example', handler);
cy.emit('example');
console.log(count); // 0

Example graph and handle setup

#cy.off(events, predicate, callback)

// Remove a delegated listener
cy.off(events: string, predicate: ElePredicate<NodeData, EdgeData>, callback: EventHandler<NodeData, EdgeData>): this

Remove a delegated handler. The predicate must be the same function object it was registered with — predicates compare by identity, not by structure.

Parameters
NameDescription
events: string

one or more space-separated event names

predicate: ElePredicate<NodeData, EdgeData>

the predicate the handler was added with

callback: EventHandler<NodeData, EdgeData>

the handler to remove

Returns this

this core, for chaining

Example

const seen = [];
const handler = event => seen.push(event.target.id());
cy.on('example', node => node.isNode(), handler);
const predicate = node => node.isNode();
cy.on('removed', predicate, handler);
cy.off('removed', predicate, handler);
cy.getElementById('a').emit('removed');
console.log(seen); // []

Example graph and handle setup

Also spelled cy.removeListener.