title: Javascript: How to get caret offset from start of content editable div with multiple lines
body: <p>I having a problem getting the caret position from the start of a content editable div using Javascript. I am able to get the offset from the --beginning of the line-- but not from the beginning of the div. The offset from the beginning of the div is what I want. For example:</p>
  
  <pre><code>This is line number one.
  This []is line number two.  &lt;-- [] Denotes where the caret position is
  </code></pre>
  
  <p>When trying to find the caret position from the --beginning of the div-- I am getting the value 6 when I really want 30.
  Here is the code I am using:</p>
  
  <pre><code>function updateCursorPosition() {
              cursorPosition = window.getSelection().baseOffset;
              alert(cursorPosition);
          }
  </code></pre>
  
  <p>This function is fired with an onclick event. As stated before, I am only getting the offset  from the beginning of the line and not the beginning of the div. Thank anyone in advanced for your input.</p>
  
  <p>The offset I am looking for is in <strong>characters</strong>, not in pixels.</p>