Web Development
How do I get cursor position in a contenteditable div?
→ Use window.getSelection().getRangeAt(0).startOffset. For nested elements, you'll need to traverse the DOM to calculate the absolute position.
Answer
How do I get cursor position in a contenteditable div?
Use window.getSelection().getRangeAt(0).startOffset. For nested elements, you'll need to traverse the DOM to calculate the absolute position.
Getting cursor position in contenteditable is more complex than in inputs because the content can have nested elements. Libraries like Rangy can simplify this task.