Reputation: 133
I need to set node selected inside my function where I create it
cy.on('tap', function (e) {
if (!e.target.id) {
let x = e.position.x;
let y = e.position.y;
let new_node = {group: "nodes", data: {id: x + '_' + y}, position: {x: x, y: y}};
cy.add(new_node);
// make node selected (click on it)
}
});
Then i will get created node data like I get it from other nodes
selected = cy.$('node:selected').jsons();
How can I do it?
Upvotes: 0
Views: 1253
Reputation: 133
The solution was simple. I added selected: true to initialisation
let new_node = {group: "nodes", data: {id: x + '_' + y}, position: {x: x, y: y}, selected: true};
Upvotes: 3
Reputation: 111
Try this
let new_node = {group: "nodes", data: {id: x + '_' + y}, position: {x: x, y: y},classes : 'selected'};
and then
cy.$('node.selected')
Upvotes: 0