Skip to content
maxkfranz edited this page Mar 8, 2012 · 9 revisions

eles.bind()

Execute a function whenever an event occurs on one of the elements in the collection.

eles.bind( eventType [, eventData], function(eventObject) )

Executes the specified callback function when the specified events occur

eventType : A space-separated list of event types to bind to the elements
eventData : A map of extra data to put in eventObject.data
function(eventObject) : The callback function to be executed when the event occurs

Details

This function calls a callback function when the corresponding event occurs, similar to jQuery.bind. Inside the callback function, the reference to this refers to the element that had the event triggered.

For programmatic triggering of events, see eles.trigger().

Examples

Bind to mouse clicks:

cy.nodes().bind("click", function(event){
  var id = this.data("id"); // `this` holds the reference to the element that triggered the event
  console.log( "Clicked node %s", id );
});

Change the color of node n0 to red on click:

cy.nodes("#n0").bind("click", function(){
  this.bypass("fillColor", "red");
});

Clone this wiki locally