d3 enter and exit

by rolfsf

HTML

<div id="example3">
        <p>Already existing paragraph 1</p>
        <p>Already existing paragraph 2</p>
     </div>

CSS

p {
             font-size: 20px;
             color: orangered;
         }

JavaScript

pdata = [10,12,6,8,15];
 
        var selectDIV = d3.select("#example3");
            
        var paragraphs = selectDIV.selectAll("p").data(pdata, function(d){return d;});
 
        paragraphs
             .enter()
             .append("p")
             .text(function(d){return d;});

        paragraphs.exit().remove();