title: get start point and end point of user selection
body: <p>I am trying to get the starting and ending points of user selection. This is the content of a DIV that I have</p>
  
  <pre><code>abc def ghi jkl mno pqr stuv wxyz
  </code></pre>
  
  <p>When I select <code>pqr</code>  The starting point becomes 1 and the ending point becomes 4 which is wrong</p>
  
  <p>When I select the whole thing, the starting point becomes 0 and the ending point becomes 33 which is right</p>
  
  <p>I have the following code:</p>
  
  <pre><code>    sel = window.getSelection();
      le = sel.toString().length;
  
      if (sel.getRangeAt &amp;&amp; sel.rangeCount)
      {
          range = window.getSelection().getRangeAt(0);
          sp = range.startOffset;
          ep = sp + le;               
      }
  </code></pre>