title: Find position of cursor in textarea
body: <p>Why isn't this code working?</p>
  
  <p><a href="http://sandbox.phpcode.eu/g/5db40.php" rel="nofollow">http://sandbox.phpcode.eu/g/5db40.php</a></p>
  
  <pre><code>&lt;form&gt;
     &lt;textarea&gt;&lt;/textarea&gt;
  &lt;/form&gt;
  &lt;script&gt;
  $(function(){
      $("textarea").keydown(function(e){
          if (e.keyCode == 9){
  
                       $("textarea").selectionStart.append("    ");
                       e.preventDefault();
          }
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>You have to press TAB on textarea</p>
  
  <p>Problem is that it doesn't do/append four spaces and it does default browser action (switch to adress tab in Chrome)</p>
  
  <p>Thoughts?</p>