5

Is there any good JQuery/JS solution to get the absolute position of a caret in text area (given in X/Y coordinates OR top/left coordinates).
The native Event object of keyDown JQuery function gives the x/y coordinates of the cursor and I want something similar the works on the working caret.

My goal is to add a floating HTML element the will be positioned relatively to the working caret position so I need to somehow get its position.



I need the solution to work on TextArea elements but a general solution to any editable html element would be even better!

Toon Krijthe
  • 51,960
  • 37
  • 141
  • 201
orshachar
  • 4,577
  • 12
  • 42
  • 65
  • u cnt but there is something that gives u the number of characters to the left – Val Feb 22 '11 at 19:32
  • @OrShachar: Have you used the plugin mentioned in the answer below? has it worked for all the editable controls in html? – Savaratkar Feb 14 '16 at 08:29
  • Unfortunately it was so long ago that I don't remember .But from my reaction it seems like it did. – orshachar Feb 28 '16 at 14:35

1 Answers1

5

may be you want replace <textarea> with <div contenteditable="true">, it has almost the same behavior, and you can get coordinates by conventional way.

Valentin Kantor
  • 1,621
  • 1
  • 22
  • 27