title: Calculating text length of node in memory with D3
body: <p>I'm trying to calculate the length of an svg <code>&lt;text&gt;</code> in memory (not in actual DOM). Is this possible? If not what are the possible solutions?</p>
  
  <p>I have the snippet below but it says</p>
  
  <blockquote>
    <p>"message": "Uncaught TypeError: text.node(...).getComputedTextLength is not a function",</p>
  </blockquote>
  
  <p>Here's the snippet:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var svg = d3.select('svg');
  var text1 = svg.append("text")
   .attr("x", 10)
   .attr("y", 30)
   .text("Hello world!");
  
  console.log("the text in DOCUMENT has " + text1.node().getComputedTextLength() + " px")
  
  var div = document.createElement('div');
  var svg = d3.select(div).append('svg');
  text2 = svg.append("text")
   .attr("x", 10)
   .attr("y", 30)
   .text("Hello world!");
  console.log("the text in MEMORY has " + text2.node().getComputedTextLength() + " px")</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://d3js.org/d3.v4.min.js"&gt;&lt;/script&gt;
  &lt;svg&gt;&lt;/svg&gt;</code></pre>
  </div>
  </div>
  </p>