views:

824

answers:

2

I'm having this annoying problem, I can't seem to get the starting and ending index of the focused text in a textarea, all I get is undefined like this:

$('#myarea').selectionStart; // return undefined

Did I do something wrong?

+3  A: 

Try:

$('#myarea')[0].selectionStart;

Why? A jQuery selector does not return the actual DOM elements but the wrapped jQuery collection. jQuery makes the actual DOM elements accessible as an array, so if you wanted to use the 1st matched element (and in this case, the only one, since it's by ID), you would do the above.

Paolo Bergantino
A: 

For managing text selections I highly recommend you the fieldSelection plugin

CMS
where can i find some fieldSelection documentation ?
kmunky