title: How to get the caret column (not pixels) position in a textarea, in characters, from the start?
body: <p>How do you get the caret position in a <code>&lt;textarea&gt;</code> using JavaScript?</p>
  
  <p>For example: <code>This is| a text</code></p>
  
  <p>This should return <code>7</code>.</p>
  
  <p>How would you get it to return the strings surrounding the cursor / selection?</p>
  
  <p>E.g.: <code>'This is', '', ' a text'</code>.</p>
  
  <p>If the word “is” is highlighted, then it would return <code>'This ', 'is', ' a text'</code>.</p>