Skip to content
Related Articles

Related Articles

How to remove SVG content?
  • Last Updated : 22 Apr, 2020

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:

  1. 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
          
        <script src = "https://d3js.org/d3.v4.min.js"></script
    </head
      
    <body style="text-align:center">  
              
      <h1 style="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() function 
            d3.select("p").remove(); 
        </script
    </body
      
    </html>                     

    Output:

  2. 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
          
        <script src = "https://d3js.org/d3.v4.min.js"></script
    </head
      
    <body style="text-align:center">  
              
      <h1 style="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() function 
            d3.selectAll("p").remove(); 
        </script
    </body
      
    </html>                     

    Output:

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :