views:

24

answers:

1

I'm trying to use A-Tools to insert something at the caret position in a TEXTAREA. However, when the TEXTAREA doesn't have focus, the stuff gets thrown at the end (I'd like it to be at the beginning). However, I don't seem to be able to figure out when that focus isn't there to insert at the beginning, as the caret position returned when it's not focused varies widely.

Is there a way to do this?/

A: 

jQuery does not have a check for focus.

  1. Add a class to the textarea.
  2. On textarea focus remove the class.
  3. Before your function runs check if the textarea has the class. If it does that means it does not have focus. So if the class is on the textarea first run .focus(), then remove the class from the textarea.

Actually while writing this I though of a simpler solution, why don't you just always run .focus() on the textarea before you run the function?

jhanifen
Would running focus in the textarea disturb the cursor position in the area?
Caveatrob