How to remove SVG content?
In order to remove SVG content, you can use the remove() function provided by D3.js. The remove() function is used along with two methods which are also provided by D3.js. Following methods are:
- Using select() Method with remove() Method: The d3.select() method is used to select the first element that need to remove.
Syntax:
d3.select("element").remove()Example: In this example, first paramgraph (p) element is removed.
<!DOCTYPE html><html><head><title>How can I remove SVG content?</title></head><bodystyle="text-align:center"><h1style="color:green">GeeksforGeeks</h1><h3> How can I remove SVG content?</h3><p>Geeks1</p><p>Geeks2</p><p>Geeks3</p><script>// Calling the selectAll() functiond3.select("p").remove();</script></body></html>Output:

- Using selectAll() Method with remove() Method: The d3.selectAll() method is used to select all the element that matched and remove it.
Syntax:
d3.selectAll("element").remove()Example: In this example, all paragraph (p) elements are removed.
<!DOCTYPE html><html><head><title>How can I remove SVG content?</title></head><bodystyle="text-align:center"><h1style="color:green">GeeksforGeeks</h1><h3> How can I remove SVG content?</h3><p>Geeks1</p><p>Geeks2</p><p>Geeks3</p><script>// Calling the selectAll() functiond3.selectAll("p").remove();</script></body></html>Output:



