Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XY Caret Coordinates inside a contenteditable div

I am looking for a way to get the caret x y coordinates inside a contenteditable div, in a similar manner to how you can get the mouse coordinates using window.event since I need to open a pop-up exactly where the user is with the caret inside the contenteditable div. How can I do this? Many thanks!

like image 939
Crista23 Avatar asked Jan 14 '23 12:01

Crista23


1 Answers

Here's one approach:

Coordinates of selected text in browser page

However, in some circumstances this will not give you coordinates, in which case you'd need to fall back to inserting an element at the caret, getting its position and removing the element again.

like image 56
Tim Down Avatar answered Feb 28 '23 13:02

Tim Down