nick34992
2/24/2017 - 5:35 PM

D3: render, .selectAll, .data, .append, selector.text: Render Text Elements, then Replace Elements

D3: render, .selectAll, .data, .append, selector.text: Render Text Elements, then Replace Elements

<!DOCTYPE html>
<html>
  <head>
    <meta name="description" content="D3byEX 2.15">
  </head>
  <body>
    <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
    <button onclick='render([5, 15]);'>Update Elements</button>
    <script>
      render([10, 20, 30]);
      function render(dataToRender) {
        var selector = d3.select('body')
          .selectAll('li')
          .data(dataToRender);
        var entering = selector.enter();
        entering.append('li')
          .text(function (d) { return d; });
        selector.text(function (d) { return d; });
      }
    </script>
  </body>
</html>