title: Select whole word with getSelection
body: <p>I want use the <code>getSelection</code> function to select words from articles to a view box.</p>
  
  <p>Here is my code: <a href="http://jsfiddle.net/xQKNh/2/" rel="noreferrer">http://jsfiddle.net/xQKNh/2/</a>.</p>
  
  <p>Now I want to ask, how to use JavaScript to select the whole word?</p>
  
  <p>For explanation,</p>
  
  <pre><code>Is your question about programming?
  </code></pre>
  
  <p>In my code, if I choose <code>r question about pro</code>, the <code>view box</code> will show </p>
  
  <pre><code>r question about pro
  </code></pre>
  
  <p>But how to make the words completed? So that it outputs:</p>
  
  <pre><code>your question about programming. 
  </code></pre>
  
  <p>Javascript code:</p>
  
  <pre><code>function getSelected() {
    if(window.getSelection) { return window.getSelection(); }
    else if(document.getSelection) { return document.getSelection(); }
    else {
      var selection = document.selection &amp;&amp; document.selection.createRange();
      if(selection.text) { return selection.text; }
      return false;
    }
    return false;
  }
  $(document).ready(function() {
    $('#content-area').mouseup(function() {
      var selection = getSelected();
      if(selection &amp;&amp; (selection = new String(selection).replace(/^\s+|\s+$/g,''))) {
          $('#show-text').html(selection)
      }
    });
  });
  </code></pre>