In my project, I am trying to add a span wherever the caret is in the contenteditable div. This span element will be used as getting the offset position of the caret indirectly.
var _spanElem = "<span class='spanPos'></span>";
Now , I can get the care position in the contenteditable div and also I know how to remove and add the span element at the caret position.
But the thing is that while I am doing this operation, Left and Right buttons are misbehaving.
Please have a look at this link
_result.remove('.spanPos'); //removing
var text = _fullText.slice(0, _caretPos) + _spanElem + _fullText.slice(_caretPos);
_result.html(text); //adding at new position
When you press right button, the span element is removing and adding to the new caret position successfully but on pressing left button, the caret is moving to initial position instead of next position.
Any fix to this?
I am looking for a solution which works in IE8+ and firefox (chrome is optional).