I do not wish to move the cursor, anywhere but when I call the function focus, it moves the cursor to the beginning. I wish to keep the cursor where it is. I am doing this in ReactJS using Typescript.
const element = document.getElementById('editable-div');
element.focus(); // sets cursor to beginning here
// rest of my code is here
I want to call focus because I need to append stuff in the contenteditable div and in some cases insert stuff. But as soon as I do focus()
, it moves the cursor at the wrong place. How do I fix this?