forked from cytoscape/cytoscape.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Collection bind
maxkfranz edited this page Mar 8, 2012
·
9 revisions
Execute a function whenever an event occurs on one of the elements in the collection.
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 ineventObject.data
function(eventObject) : The callback function to be executed when the event occurs
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().
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");
});