Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get caret XY coordinates in text area [duplicate]

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!

like image 842
orshachar Avatar asked Feb 22 '11 19:02

orshachar


1 Answers

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

like image 150
Valentin Kantor Avatar answered Sep 23 '22 16:09

Valentin Kantor