0

I have already asked another question: How to set caret position in a contenteditable after I append a span into it; and move caret to the end of the span?

My code adds the span tag and then modifies the innerHTML of the content editable element like;

contenteditable.innerHTML = newModifiedDataWithSpan;

but this causes my contenteditable to lose focus. If I use focus() on the element, the caret moves to the beginning of the contenteditable. Is there anyway to append a unicode character to the end my inputted span, and then search for said character, remove it and move caret to that position?

Steve Chacko
  • 95
  • 11
  • Does this answer your question? [How to move cursor to end of contenteditable entity](https://stackoverflow.com/questions/1125292/how-to-move-cursor-to-end-of-contenteditable-entity) – bloodyKnuckles Sep 28 '22 at 21:44
  • @bloodyKnuckles sorry this just moves the cursor to the end of the contentEditable. I am trying to insert a span with a unicode character \u2006 at the end of it, and using range to delete it, so the cursor will appear there – Steve Chacko Sep 28 '22 at 23:08
  • Does this help? https://stackoverflow.com/questions/1181700/set-cursor-position-on-contenteditable-div – bloodyKnuckles Sep 28 '22 at 23:31
  • @bloodyKnuckles thanks but I used another method detailed in my answer below – Steve Chacko Sep 29 '22 at 09:53

0 Answers0