title: How to insert an element at selected position in HTML document?
body: <p>I want to insert an element(span,div etc) at the position determined by user selection of text in the document.</p>
  
  <p>I was able to get the element on which selection is made. But I am not able to get the exact position where the selection is made.</p>
  
  <p>For example:</p>
  
  <pre><code>&lt;span&gt;this is testing string for testing purpose&lt;/span&gt;
  </code></pre>
  
  <p>In this, lets assume that user selected 2nd 'testing' word. I want it to be replaced like </p>
  
  <pre><code>&lt;span&gt;this is testing string for &lt;b&gt;testing&lt;/b&gt; purpose&lt;/span&gt;
  </code></pre>
  
  <p>How do i do it?</p>
  
  <p>BTW: I know it is possible. Google Wave does it. I just dont know how to do it</p>