Removing an element by ID (jointJS)

Viewed 7568

I noticed that JointJS links can be removed by hovering over them and clicking the big red X that appears. But I was wondering if it is possible remove an element once it has been created, without knowing the variable name.

onCreateButtonClick(function(){
  var rect = new joint.shapes.basic.Rect({
    position: { x: 100, y: 30 },
    size: { width: 100, height: 30 }
  });
  graph.addCell([rect]);
});

onRemoveButtonClick(function(){
   //removeRectangle here?
});

My question is: can I remove this rectangle in the second function?

2 Answers

I implemented the removal of an element by single clicking the element , using the cellView arguement directly.

paper.on('cell:pointerclick', function(cellView, evt, x, y) {
    cellView.remove();
});
Related