In jQuery I can clear/empty a div with the following:
$("#graph").empty()
so the above command would clear/empty the following div if it had any tags inside it <div id="graph"></div>.
Is there an equivalent way to do this is d3?
see my PLUNKER here
Snippet of Plunker code here:
<div id="mylist">hello test1</div>
<div id="graph">hello test2</div>
<script>
$("#graph").empty() // comment out to not empty the div
</script>
PLUNKER for my reference based on answer below.
The official way to do this is to use .html(null), as in
d3.select("#graph").html(null);
You have two options:
You could use .html("") and basically wipe the html content of the element you have selected.
Or if you want to delete a specific d3 selection you can go for .remove().
The remove method will remove the selection itself, whereas emptying out the html just takes care of all child nodes.
So for your case probably d3.select('#graph').html("").
I modified your Plunker to use d3: https://plnkr.co/edit/V2tYVxOTbzMUX3D7m57L?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With