I have a simple contenteditable div with some text in it. On onkeyup event i want to replace whole content (innerHTML) of the div based on regex.
For example,
HT
You know which text you are replacing. So you know the position of that text . there only you going to put the new text. Then also the position is same.After writing new html , yu can set cursor.
for eg
I dont undertsand the question
position of question is 5 an i replace it
I dont undertsand the answer
make the cursor position to 5
http://ajaxian.com/archives/javascript-tip-cross-browser-cursor-positioning
http://hartshorne.ca/2006/01/23/javascript_cursor_position/
http://geekswithblogs.net/svanvliet/archive/2005/03/24/textarea-cursor-position-with-javascript.aspx