All that’s left to do, then, is to remove the exiting elements:
circle.exit().remove();
The enter, update and exit selections are computed by the data operator, and don’t change when you append or remove elementst least until you call selectAll again. So, if you keep variables around that point to selections (such as circle
, above), you’ll probably want to reselect after adding or removing elements.