I'm trying to keep the cursor at specific character in contentEditable div when .focus() event occurs.
That is I've content editable div(.textA) with following content:
<div class='textA' contentEditable='true'>
Hello There to all <div class='xyz' contentEditable='true'>SO</div> Users.<br>
Can you all Please <div class='abc'>Solve</div> This for me?<br>
<br>
<br>
<div class='xyz'>VT</div>
</div>
Then I'm trying to develop a function placeCaretAt(position) in javascript in such a way that,
it'll place cursor at positionth character from the .text() of that div on focus event.
ie, for ex: when it is called as
$('.textA').focus(function(){
placeCaretAt(20);
});
then it should place cursor in between S & O of SO users like <div class='xyz' contentEditable='true'>S|O</div>.
for getting text without tags from contentEditable I use .text() of Jquery.
Can experts here please help me? any help/advice/suggestions are welcome :). Thanks in advance.
I had already seen:
How to set caret(cursor) position in contenteditable element (div)?
jquery Setting cursor position in contenteditable div
Set cursor position on contentEditable <div>
But they were of no use for me. Bad Luck and a day :(. Please Help me experts.