title: How to linebreak an svg text in javascript?
body: <p>I am starting with d3.js, and am trying to create a network graph each circle of which contains a label.</p>
  
  <p>What I want is a line break an svg text.</p>
  
  <p>What I am trying to do is to break the text into multiple <code>&lt;tspan&gt;</code>s, each with x="0" and variable "y" to simulate actual lines of text. The code I have written gives some unexpected result.</p>
  
  <pre><code>var text = svg.selectAll("text").data(force.nodes()).enter().append("text");
  
  text       
   .text(function (d) {
   arr = d.name.split(" ");
   var arr = d.name.split(" ");
   if (arr != undefined) {
    for (i = 0; i &lt; arr.length; i++) {
     text.append("tspan")
      .text(arr[i])
      .attr("class", "tspan" + i);
    }
   }
  });
  </code></pre>
  
  <p>In this code am splitting the text string by white space and appending the each splitted string to tspan. But the text belonging to other circle is also showing in each circle. How to overcome this issue?</p>
  
  <p>Here is a JSFIDDLE <a href="http://jsfiddle.net/xhNXS/" rel="noreferrer">http://jsfiddle.net/xhNXS/</a> with only svg text</p>
  
  <p>Here is a JSFIDDLE <a href="http://jsfiddle.net/2NJ25/16/" rel="noreferrer">http://jsfiddle.net/2NJ25/16/</a> showing my problem with tspan.</p>