title: How do you get the cursor position in a textarea?
body: <p>I have a textarea and I would like to know if I am on the last line in the textarea or the first line in the textarea with my cursor with JavaScript.</p>
  
  <p>I thought of grabbing the position of the first newline character and the last newline character and then grabbing the position of the cursor.</p>
  
  <pre><code>var firstNewline = $('#myTextarea').val().indexOf('\n');
  var lastNewline = $('#myTextarea').val().lastIndexOf('\n');
  
  var cursorPosition = ?????;
  
  if (cursorPosition &lt; firstNewline)
      // I am on first line.
  else if (cursorPosition &gt; lastNewline)
      // I am on last line.
  </code></pre>
  
  <ul>
  <li>Is it possible to grab the cursor position within the textarea?</li>
  <li>Do you have a better suggestion for finding out if I am on the first or last line of a textarea?</li>
  </ul>
  
  <p>jQuery solutions preferred unless JavaScript is as simple or simpler.</p>