title: Wrap Text In JavaScript
body: <p>I am new to JavaScript and jQuery. </p>
  
  <p>I have a variable named as <code>str</code> in JavaScript and it contains very long text, saying something like</p>
  
  <pre><code>"A quick brown fox jumps over a lazy dog". 
  </code></pre>
  
  <p>I want to wrap it and assign it to the same variable <code>str</code> by inserting the proper <code>\n</code> or <code>br/</code> tags at the correct places. </p>
  
  <p>I don't want to use CSS etc. Could you please tell me how to do it with a proper function in JavaScript which takes the <code>str</code> and returns the proper formatted text to it?</p>
  
  <p>Something like:</p>
  
  <pre><code>str = somefunction(str, maxchar);
  </code></pre>
  
  <p>I tried a lot but unfortunately nothing turned up the way I wanted it to be! :(</p>
  
  <p>Any help will be much appreciated...</p>