This question already has an answer here:
- How do I get the (x, y) pixel coordinates of the caret in text boxes? 3 answers
I'd like to display a dropdown list in a <textarea>
to assist the user in typing certain things. You know this from current IDEs as code completion. As you start typing something, a popup will appear right a the current cursor/caret location and you can navigate it using arrow keys to complete your text input.
I know how to get the cursor position in the text string (i.e. the character index of the cursor position) but I do not know how to get the X/Y coordinates (something like offsetWidth
and offsetHeight
) of the cursor inside the <textarea>
element so that I can position my list element there. Is that possible in HTML/JavaScript, and how would it work?