title: HTML document selection using javascript
body: <p>I use this javascript code to get the currently highlighted selection.</p>
  
  <pre><code>var selection = window.getSelection()
  </code></pre>
  
  <p>If the highlight is a section of text all within a <code>&lt;div&gt;</code>, how can I get the offset from the beginning of the <code>&lt;div&gt;</code> and the length of the highlight? (the length is not just the length of the text, it should be the actual length of the html code for that text)</p>