selectionStart of textarea returns wrong value
<p>I have a textarea with onfocus event. I want to find out the line number on which the cursor is when the user clicks on it.</p>

<p>Here's what I have in the onfocus event:</p>

<pre><code>function onFocusFunction(){
    var lineNr = $('#textAreaId').val().substr(0, $('#textAreaId')[0].selectionStart).split("\n").length;
}
</code></pre>

<p>Here's the problem:</p>

<p>My text area is empty, it has four lines, so it contains this: \n\n\n\n</p>

<p>The first time onFocusFunction is called, $('#textAreaId')[0].selectionStart returns 1, no matter which line was clicked. After that it works great. What's causing this and is there a workaround for this?</p>
