HowEnterAndExitWork

by Simon Raper

JavaScript

d3.select("body").selectAll("div")
    .data([4, 8, 15, 16, 23, 42])
  .enter().append("div")
    .text(function(d) { return d; });

var div = d3.select("body").selectAll("div")
    .data([1, 2, 4, 8, 16, 32], function(d) { return d; });

div.enter().append("div")
    .text(function(d) { return d; });

div.exit().remove();