Get cursor pixel position in ContentEditable

I created a contentEditable editor and I need to get the pixel position of the cursor so that I can position its menu. (As the user enters a special line, the menu opens automatically to show a hint).

All this works for me, except that I do not know how to get the actual cursor pixel position for positioning the menu. The best I managed to do was get the current node cursor, but I still don't know where the cursor is inside this element.

↓ I can get the position of this div easily enough <div>I am typing a message |</div> ↑ But I need the position of the cursor here 

Change I can confirm that using Range, as in the text box , also works for ContentEditable.

+4
source share

Source: https://habr.com/ru/post/1485588/


All Articles