Problem with two JavaScript codes
<p>I have these two codes - </p>

<pre><code>new function($) {
$.fn.getCursorPosition = function() {
var pos = 0;
var el = $(this).get(0);
// IE Support
if (document.selection) {
    el.focus();
    var Sel = document.selection.createRange();
    var SelLength = document.selection.createRange().text.length;
    Sel.moveStart('character', -el.value.length);
    pos = Sel.text.length - SelLength;
}
// Firefox support
else if (el.selectionStart || el.selectionStart == '0')
    pos = el.selectionStart;

return pos;
}
} (jQuery);
</code></pre>

<p>And</p>

<pre><code>var element = document.getElementById('txtarr');
if( document.selection ){
      // The current selection
    var range = document.selection.createRange();
      // We'll use this as a 'dummy'
    var stored_range = range.duplicate();
      // Select all text
    stored_range.moveToElementText( element );
      // Now move 'dummy' end point to end point of original range
    stored_range.setEndPoint( 'EndToEnd', range );
      // Now we can calculate start and end points
    element.selectionStart = stored_range.text.length - range.text.length;
    element.selectionEnd = element.selectionStart + range.text.length;
}
</code></pre>

<p>The first one is for getting the cursor position in a textarea and the second one is for determining the end of a textarea ,but they give the same result?
Where's the mistake?</p>
