Reputation: 21
The code adds a node dynamically but mouseover
doesn't trigger for node "c"
// Mouseover function just give id node and position
cy.$('node').on('mouseover', function(evt) {
var myClickedID = evt.cyTarget.id();
console.log(myClickedID);
console.log(cy.$('#' + myClickedID).position());
});
// add a node dynamicaly
cy.$('node').on('click', function(evt) {
var elements = cy.add({
group: 'nodes',
data: { id: 'c' }
});
});
Upvotes: 1
Views: 452
Reputation: 12242
You didn't bind to events on the added node. It's the exact same behaviour in the DOM. You can't expect that setting a listener on prior elements will automatically set listeners on newly added elements.
Use a delegate selector if you want to bind only once: http://js.cytoscape.org/#cy.on
Upvotes: 1