Accepted answer

FIDDLE with a quick example of adding, removing and the adding again an SVG and a contained circle. Hope this helps.

function update() {
    svg = d3.selectAll("body").append("svg");


I had a similar problem to this. removing the SVG element did not allow me to fully update the data like I wanted.

Instead, I removed the g elements created inside the SVG with this line:

d3.selectAll("g > *").remove()

in my updateGraph() function

Full explanation and situation shown here: Repainting/Refreshing Graph in D3

Related Query