title: Cut a string after n characters, but if it's in the middle of a word cut the whole word
body: <p>I'm trying to make a JS function that cuts a string after n characters - that works. The problem is if it's in the middle of a word it looks bad, so I need your help making it cut the whole word if it's the middle of it.</p>
  
  <p>My code so far:</p>
  
  <pre><code>if($('#desc').text().length &gt; 505){
    str = $("#desc").text();
    $('#desc').text(str.substring(0, 505)).append('...');
  }
  </code></pre>
  
  <p>P.S</p>
  
  <ul>
  <li>#desc is the div that contains my string.</li>
  <li>you can use jQuery.</li>
  </ul>