How can I remove or replace SVG content?
Here is the solution:
d3.select("svg").remove();
This is a remove
function provided by D3.js.
If you want to get rid of all children,
svg.selectAll("*").remove();
will remove all content associated with the svg.
Setting the id attribute when appending the svg element can also let d3 select so remove() later on this element by id :
var svg = d3.select("theParentElement").append("svg")
.attr("id","the_SVG_ID")
.attr("width",...
...
d3.select("#the_SVG_ID").remove();